akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=75,mo=1e9+7;
int n,k,_N;
char s[N];
int cnt[N],a[N],mrk[N],f[N],st[N],t,sf[N];
ll Ans,jc[N*10],ny[N*10];
ll power(ll a,ll b=mo-2){
	ll ans=1;
	while (b){
		if (b&1)ans=ans*a%mo;
		a=a*a%mo;
		b>>=1;
	}return ans;
}
ll C(ll n,ll m){
//	if (n<m||m<0)return 0;
	assert(n>=m);
	assert(m>=0);
	return ny[m]*ny[n-m]%mo*jc[n]%mo;
}
int check(int n){
	if (n==0){
		Ans++;
		return 1;
	}
	memset(mrk,0,sizeof mrk);
	memset(f,0,sizeof f);
	memset(sf,0,sizeof sf);
	if (!st[n])return 0;
	for (int i=1;i<=n;i++)mrk[st[i]]=1;
	for (int i=1;i<=n;i++){
		if (a[i]==1)break;
		for (int j=max(st[i],f[i-1])+1;s[j];j++)
			if (s[j]=='b'){
				f[i]=j;
				mrk[j]=1;
				break;
			}
		if (!f[i])return 0;
	}
	for (int i=k;i>=1;i--)
		sf[i]=sf[i+1]+(!mrk[i]);
	int s1=0;
	for (int i=n;i>=1;i--){
		s1+=max(0,a[i]-2);
		if (sf[f[i]]<s1)return 0;
	}
	ll n1=1,m1=2,ans=1,sum=0;
	for (int i=1;i<=_N;i++)
		sum+=cnt[i],ans=ans*ny[cnt[i]]%mo;
	ans=ans*jc[sum]%mo;
	for (int i=1;i<=n;i++)
		n1+=2*a[i],m1+=2*(a[i]>=2);
	ans=ans*C(_N+m1-1,n1-1);
	Ans=(Ans+ans)%mo;
	return 1;
}
int ccnt=0;
void dfs(int x,int s,int la){
	if (s>n+1)return;
	if (!check(x-1))return;
	for (int i=1;i<=la;i++){
		a[x]=i;
		cnt[i]++;
		dfs(x+1,s+max(2,2*(i-1)),i);
		cnt[i]--;
	}
}
int main(){
	cin>>n>>k;_N=n;
	jc[0]=ny[0]=1;
	for (int i=1;i<=700;i++)jc[i]=jc[i-1]*i%mo;
	ny[700]=power(jc[700]);
	for (int i=700;i>=1;i--)ny[i-1]=ny[i]*i%mo;
	scanf("%s",s+1);
	for (int i=1;i<=k;i++){
		if (s[i]=='r')st[++t]=i;
	}
	dfs(1,0,n+1);
	cout<<Ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int n,q,v[300005],w[300005];
int dp[1<<9][100005],p[20],r[20];
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>v[i]>>w[i];
    }
    int m=min(n,(1<<9)-1);
    for(int i=w[0];i<100001;i++){
        dp[0][i]=v[0];
    }
    for(int i=1;i<m;i++){
        for(int j=0;j<100001;j++){
            if(j<w[i]) dp[i][j]=dp[(i-1)/2][j];
            else dp[i][j]=max(dp[(i-1)/2][j],dp[(i-1)/2][j-w[i]]+v[i]);
        }
    }
    cin>>q;
    while(q--){
        int x,l,s=0,ans=0;
        cin>>x>>l;
        x--;
        while(x>=m){
            p[s]=v[x];
            r[s]=w[x];
            s++;
            x=(x-1)/2;
        }
        for(int i=0;i<1<<s;i++){
            int t=l,u=0;
            for(int j=0;j<s;j++){
                if(i>>j&1){
                    t-=r[j];
                    u+=p[j];
                }
                if(t<0) break;
            }
            if(t>=0){
                ans=max(ans,u+dp[x][t]);
            }
        }
        cout<<ans<<endl;
    }

}



Measured memory_bytes: 205288
H, N = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]

dp = [[10**9]*(H+1) for _ in range(N+1)]
dp[0][0] = 0

for i in range(1, N+1):
    for j in range(H+1):
        a, b = ab[i-1]
        if j < a:
            dp[i][j] = min([dp[i-1][0]+b, dp[i-1][j]])
        else:
            dp[i][j] = min([dp[i][j-a]+b, dp[i-1][j]])
print(dp[N][H])


Measured memory_bytes: 119788
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>

#include <cstdio>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	ll N;
	ll div;

	cin >> N;

	for (ll i = 1; i * i <= N; i++) {
		if (N % i == 0) div = N / i;
	}

	cout << (int)log10(div) + 1 << endl;

	return 0;
}

Measured memory_bytes: 256
c = [[int(i) for i in input().split()] for i in range(3)]
ans = 'Yes'
for j in range(2):
  if c[j][0]-c[j+1][0] == c[j][1]-c[j+1][1] == c[j][2]-c[j+1][2]:
    ans = 'Yes'
  else:
    ans = 'No'
    print(ans)
    exit()
for j in range(2):
  if c[0][j]-c[0][j+1] == c[1][j]-c[1][j+1] == c[2][j]-c[2][j+1]:
    ans = 'Yes'
  else:
    ans = 'No'
    print(ans)
    exit()
print(ans)

Measured memory_bytes: 3064
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#solve
def solve():
    n = II()
    ans = 0
    N = int(sqrt(n))+2
    d = defaultdict(int)
    d[1] = 1 
    for i in range(2, int(sqrt(n - 1)) + 2):
        if d[i] == 0:
            x = i
            while 1:
                if n % x == 0 and d[x] != 1:
                    ans += 1
                    n //= x
                    d[x] = 1
                else:
                    break
                x *= i
            l = i
            j = 1
            while l < N:
                d[l] = 1
                j += 1
                l = i * j
    if d[n]:
        print(ans)
    else:
        print(ans + 1)
    return


#main
if __name__ == '__main__':
    solve()


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


int main(){
    int x, y;
    cin >> x >> y;
    
    int cnt=0;
    while(true){
        if(abs(x)==abs(y)){
            if(x==y) break;
            else {
                cnt++;
                break;
            }
        }
        if((x>=0&&y>=0&&abs(x)-abs(y)>=0) || (x>=0&&y<0&&abs(x)-abs(y)>=0) || (x<0&&y>=0&& abs(x)-abs(y)<0) || (x<0&&y<0&&abs(x)-abs(y)<0)){
            x *= -1;
            cnt++;
        }
        else {
            cnt += abs(abs(x)-abs(y));
            x += abs(abs(x)-abs(y));
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

const int MAX_N = 1e5 + 5;
const int MAX_L = 20; // ~ Log N
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;

#define rep(i,n) for (int i = 0; i < n; ++i)
#define REP(i,k,n) for (i = k; i <= n; ++i)
#define REPR(i,k,n) for (i = k; i >= n; --i)

#define LSOne(S) (S & (-S))
#define isBitSet(S, i) ((S >> i) & 1)


#define X 500010

int bit[X];

void init(){
    for (int & i : bit) {
        i = 0;
    }
}

int sum(int i) {
    int ans = 0;
    for (i++; i > 0; i -= i & -i) {
        ans += bit[i];
    }
    return ans;
}

int sum(int i, int j) {
    return sum(j) - sum(i-1);
}

void add(int i, int d) {
    for (i++; i < X+1; i += i & -i) {
        bit[i] += d;
    }
}


#define MAX 500010
int N, Q;
int color[MAX];
int prevColor[MAX];
int ans[MAX];
vector<int> ql[MAX],qid[MAX];
void solve() {
    cin >> N >> Q;
    rep(i, N) {
        int c;
        cin >> c;
        c++;
        color[i] = c;
    }
    memset(prevColor, -1, sizeof(prevColor));
    rep(i, Q) {
        int l, r;
        cin >> l >> r;
        l--;r--;
        ql[r].push_back(l);
        qid[r].push_back(i);
    }
    init();
    rep(i, N) {
        if (prevColor[color[i]] != -1) {
            color[prevColor[color[i]]] = 0;
            add(prevColor[color[i]], -1);
        }
        prevColor[color[i]] = i;
        color[i] = 1;
        add(i, +1);
        for (int j = 0; j < ql[i].size(); j++) {
            ans[qid[i][j]] = sum(ql[i][j], i);
        }
    }
    rep(i, Q) {
        cout << ans[i] << "\n";
    }
}

//#define LOCAL 1

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

#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    solve();

    return 0;
}

Measured memory_bytes: 53068
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#define REP(i,N) for(int i=0;i<N;++i)
using namespace std;

int main(){
  int N;
  cin>>N;
  vector<int> line(N);
  REP(i, N){
    cin >> line[i];
  }
  vector<int> ans;
  while(!line.empty()){
    int pl = -1;
    REP(i,line.size()){
      if(line[i] == i + 1){
        pl = i;
      }
    }
    if(pl==-1){
      cout << -1 << endl;
      return 0;
    }
    ans.push_back(pl+1);
    line.erase(line.begin() + pl);
  }
  reverse(ans.begin(),ans.end());
  REP(i,N){
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main()
{
    int x = 0;
    
    for( int i = 1; i <= 10000; ++i )
    {
        // input
        std::cin >> x;

        // output
        if( x >= 1 && x <= 10000 )
        {
            std::cout << "Case " << i << ": " << x << std::endl;
        }
        else if( 0 == x )
        {
            break;
        }
    }
    
    return 0;
}


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

#define pb push_back
#define all(a) a.begin(), a.end()

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

const int N = 1e5 + 5;
const ll mod = 1e9 + 7;
int cnt[N];

int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    int n; cin >> n;
    cnt[0] = 3;
    ll ans = 1;
    for (int i = 1; i <= n; ++i) {
    	int a; cin >> a;
    	++a;
    	ans *= cnt[a - 1];
    	ans %= mod;
    	++cnt[a];
    	--cnt[a - 1];
    }
    cout << ans << "\n";
}

Measured memory_bytes: 640
def debug(*args):
    if 1 == 1:
        print(*args)

def solve(N, A):
    A[0] -= 1
    for i in range(1, N):
        if A[i-1] <= A[i] - 1: # 下げれるなら下げる
            A[i] -= 1
        if A[i-1] > A[i]:
            return "No"
    return "Yes"

def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    print(solve(N, A))

main()






Measured memory_bytes: 14252
r, g, b, n = map(int, input().split())

ans = 0

for i in range(3001):
    if i*r > n:
        break
    for j in range(3001):
        value = r*i + g*j
        if (n - value) < 0:
            break
        elif (n - value) % b == 0:
            ans += 1
print(ans)


Measured memory_bytes: 40684
a,b=map(int,input().split())
L=[[] for i in range(a)]
u=0
# i番目の県の情報（[i，年，入力順]）をLのi番目に入れる
for i in range(b):
    u+=1
    c=list(map(int,input().split()))
    c.append(u)
    L[int(c[0])-1].append(c)
# Lの要素を年でソート
for i in L:
    i.sort(key=lambda x:x[1])
#　ソートしたので、要素ごとに何番目にできたかを末尾に付け加えておく
for i in L:
    e=0
    for j in i:
        e+=1
        j.append(e)
q=[]
for w in L:
   q.extend(w)# flatten
# 入力順に並べ替えて、入力した順に出力できるようにする
q.sort(key=lambda x:x[2])
for r in range(b):
        print(str(q[r][0]).zfill(6)+str(q[r][3]).zfill(6))# zfill

Measured memory_bytes: 43172
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    int minute[5];

    int last_dish_ind = -1;
    int yu = 0;

    for(int i=0; i<5; ++i){
        cin >> minute[i];

        int temp_yu = 0;
        if(minute[i] % 10 != 0) temp_yu = ((minute[i] / 10)+1)*10 - minute[i];

        if ( temp_yu >= yu ){
            last_dish_ind = i;
            yu = temp_yu;
        }
    }

    int sum=0;
    for(int i=0; i<5; ++i){
        if(i == last_dish_ind) sum += minute[i];
        else{
            if(minute[i] % 10 != 0){
                sum += (minute[i] / 10 + 1)*10;
            }else{
                sum += minute[i];
            }
        }
    }
    
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
typedef vector<int> vec;
typedef vector<int64> vec64;
#define ss cout << " ";
#define nn cout << "\n";
#define ct(x) cout << x;
#define cts(x) cout << x << " ";
#define ctn(x) cout << x << "\n";
#define db(x) cout << "> " << #x << ": " << x << "\n";
#define qr queries();
void solve();
void YN(bool b){if (b){ctn("YES");}else{ctn ("NO");}};
void yn(bool b){if (b){ctn("Yes");}else{ctn ("No");}};
void queries(){int n;cin >> n;while (n--)solve();}
// // // // // // // // // // // // // // // // // // // // // // 
/*                  TEMPLATE - VANILLA                         */
// // // // // // // // // // // // // // // // // // // // // //
const int maxn = 200200;
 
void solve(){

    return;
}
 
 
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    int count = 0;
    int rs = 0;
    for (int i = 0; i < n; i++){
        if (s[i] == 'R'){
            count++;
        }
    }
    rs = count;
    for (int i = 0; i < count; i++){
        if (s[i] == 'R'){
            rs--;
        }
    }
    ctn(rs);
    return 0;
}

Measured memory_bytes: 3776
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstring>
#include<utility>

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int N, K, Q;
int A[2020];
int B[2020];

int calc(int v) {
    int num = 0;
    vector<int> candidates;
    vector<int> group;
    rep(i, N) {
        if (A[i] < v) {
            if (num != 0) {
                sort(group.begin(), group.end());
                rep(j, num - K + 1) {
                    candidates.push_back(group[j]);
                }
                num = 0;
                group.clear();
            }
        } else {
            ++num;
            group.push_back(A[i]);
        }
    }
    if (num != 0) {
        sort(group.begin(), group.end());
        rep(j, num - K + 1) {
            candidates.push_back(group[j]);
        }
        num = 0;
        group.clear();
    }

    if (candidates.size() < Q)return INF;
    sort(candidates.begin(), candidates.end());
    return candidates[Q - 1] - candidates[0];
}

signed main() {
    cin >> N >> K >> Q;
    rep(i, N) {
        cin >> A[i];
        B[i] = A[i];
    }
    sort(B, B + N);
    int k = 0;
    int ans = INF;
    while (k < N) {
        ans = min(ans, calc(B[k]));
        while (k + 1 < N && B[k + 1] == B[k])++k;
        ++k;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

/*
ソート：sort(v.begin(),v.end(), 0)
合計：accumulate(v.begin(),v.end(), 0)
最小値：*min_element(v.begin(),v.end())
最大値：*max_element(v.begin(),v.end())
最大公約数：__gcd(a,b)
*/

int main(int argc, char const *argv[]){
    int n,d;
    cin >> n >> d;
    cout << (n-1)/(2*d+1)+1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
unordered_map<ll,ll>dp;

ll solve(ll*a,ll n){
    if(n==2){
        return abs(a[0]-a[1]);
    }
    
    dp[0]=a[0];
    dp[1]=abs(a[0]-a[1]);
    dp[2]=min( (abs(a[2]-a[1])+dp[1]), abs(a[2]-a[0]) );
    
    for(ll i=3;i<n;i++){
        ll opt1 = abs(a[i]-a[i-1]) + dp[i-1];
        ll opt2 = abs(a[i]-a[i-2]) + dp[i-2];
        
        dp[i] = min(opt1,opt2);
        // cout<<i<<" : "<<dp[i]<<endl;
    }
    return dp[n-1];
}

int main(){
    ll n;cin>>n;
    ll a[n];
    for(ll i=0;i<n;i++){
        cin>>a[i];
    }
    
    cout<<solve(a,n)<<endl;
}

Measured memory_bytes: 5156
PROGRAM RALLY

      INTEGER N,X(100)
      INTEGER MIN,TOTAL

      MIN=1000000000

      READ(*,*) N

!      DO 100 I=1,N
!        READ(*,*) X(I)
!  100 CONTINUE

!      READ(*,*) X(1),X(2),X(3),X(4)
      READ(*,*) X(1:N)

      DO 200 I=1,100
        TOTAL=0

        DO 300 J=1,N
          TOTAL=TOTAL+(X(J)-I)*(X(J)-I)
  300   CONTINUE

        IF(TOTAL.LT.MIN) MIN=TOTAL

  200 CONTINUE

      WRITE(*,*)MIN

      STOP
      END


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<ll, ll>
#define SZ(x) ((int)(x).size())
#define endl "\n"
#define vvi vector<vector<int> >
#define vvl vector<vector<long long> >
ll mod = 1e9 + 7;
//const double pi = acos(-1.0);
/*
ll kmp(string x)
{
    ll n= x.length();
    //cout<<x<<endl;
    vector<ll> lcp(x.length(), 0);
    for(ll i=1;i<n;i++)
    {
        ll j=lcp[i-1];
        while(j>0 && x[j]!=x[i])
            j=lcp[j-1];
        if(x[i]==x[j])
            j++;
        lcp[i]=j;
    }
    return lcp[n-1];
}

int N = 1000002;
int ar[100002];
void sieve()
{
    for(int i=1;i<=N;i++)
        ar[i] = 1;
    ar[0] = 0;
    for(int i=2;i*i<=N;i++)
    {
        if(ar[i] && i*i<=N)
        {
            for(int j = i*i; j<=N;j+=i)
                ar[j] = 0;
        }
    }
}

ll modex(ll a,ll b){
    if(b<=0){
        return 1;
    }
    if(b%2==0)
    {
        ll x = modex(a, b/2);
        return ((x*x)%mod);
    }
    else
        return ((a%mod * modex(a, b-1))%mod);
}

ll c[1010][1010];

ll combina(ll i, ll j){
        for (int i=0;i<=1005;i++)
        for (int j=0;j<=i;j++)
        {
            if (j==i||j==0)
                c[i][j]=1;
            else
            c[i][j]=c[i-1][j-1]+c[i-1][j];
            c[i][j]%=mod;
        }
        return c[i][j];
}
void find_fac(int x){
    vector<ll> di;
    for(ll i = 2; i*i <= x; i++)
    {
        if(x%i==0){
            di.push_back(i);
            while(x%i==0)
                x/=i;
        }
    }
    if(x > 1)
        di.push_back(x);
}
*/
int n;
vector<ld> h;
vector<ld> t;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout<<fixed;
    cout.precision(12);
    cin>>n;
    h.resize(n+1);
    t.resize(n+1);
    for(int i=1;i<=n;i++)
    {
        cin>>h[i];
        t[i] = 1-h[i];
    }
    vector<vector<ld> > dp(n+1, vector<ld> (n+1, 1));
    for(int i=1;i<=n;i++){
        for(int j=0;j<=i;j++){
            dp[i][j]=0;
            if(j!=i)
                dp[i][j] = dp[i-1][j] * t[i];
            if(j>=1)
                dp[i][j] += dp[i-1][j-1] * h[i];
        }
    }
   /* for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++)
            cout<<dp[i][j]<<" ";
        cout<<endl;
    }*/
    ld an = 0;
    for(int j=(n+1)/2;j<=n;j++){
        an += dp[n][j];
    }
    cout<<an<<endl;
    return 0;
}


Measured memory_bytes: 144228
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		long count = 1;
		while (true) {
		    long d = count * (count + 1) / 2;
		    if (d >= x) {
		        System.out.println(count);
		        return;
		    }
		    count++;
		}
	}
}


Measured memory_bytes: 23764
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define next qtyQTYqtyQTY
#define index QTYqtyQtyqty
#define rep(i,n) for (int i=0;i<n;++i)
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define read(x) scanf("%d",&x)
int n;
typedef pair<pii,pii> data;// (x,y),(segment)
priority_queue<data,vector<data>,greater<data> > q;
int index[200005];
const int INF=1e7;
int mn[2][530005];
int dat[200005];
inline void build(int v=1,int l=1,int r=n){
	if (l==r){
		mn[l&1][v]=dat[l];
		mn[!(l&1)][v]=INF;
		return;
	}
	int m=l+r>>1;
	build(v<<1,l,m);
	build(v<<1|1,m+1,r);
	mn[0][v]=min(mn[0][v<<1],mn[0][v<<1|1]);
	mn[1][v]=min(mn[1][v<<1],mn[1][v<<1|1]);
}
inline int query(bool type,int a,int b,int v=1,int l=1,int r=n){
	if (r<a||l>b) return INF;
	if (a<=l&&r<=b) return mn[type][v];
	int m=l+r>>1;
	return min(query(type,a,b,v<<1,l,m),query(type,a,b,v<<1|1,m+1,r));
}
inline data get(int a,int b){
	int x=query(a&1,a,b);
	int px=index[x];
	int y=query(!(a&1),px+1,b);
	return mp(mp(x,y),mp(a,b));
}
inline void split(data t){
	cout<<t.F.F<<' '<<t.F.S<<' ';
	int px=index[t.F.F],py=index[t.F.S],a=t.S.F,b=t.S.S;
	if (a<px-1) q.push(get(a,px-1));
	if (px+1<py-1) q.push(get(px+1,py-1));
	if (py+1<b) q.push(get(py+1,b));
}
int main(){
	ios::sync_with_stdio(false);
	cin>>n;
	for (int i=1;i<=n;++i){
		int x;cin>>x;
		dat[i]=x;index[x]=i;
	}
	build();
	q.push(get(1,n));
	while(!q.empty()){
		data tp=q.top();
		q.pop();
		split(tp);
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 7924
n = int(input())
k = int(input())


num = []
while n != 0:
  num.append(n % 10)
  n = n//10
num.reverse()

# num
i = 0
while(1):
    if num[i]>1:
        print(num[i])
        break
    else:
        if k==1:
            print(1)
            break
        else:
            k-=1
    i+=1
    

Measured memory_bytes: 3060
//B - Good Distance
//20190912

using System;
using System.Linq;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] nd = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = nd[0];
            int D = nd[1];

            var X = new int[N][];

            for (int i = 0; i < N; i++)
            {
                X[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();
            }

            int count = 0;

            for (int i = 0; i < N-1; i++)
            {
                for (int j = i + 1; j < N; j++)
                {
                    double dist = 0;
                    for (int k = 0; k < D; k++)
                    {
                        dist += Math.Pow(X[i][k] - X[j][k],2);
                    }

                    dist = Math.Sqrt(dist);
                    int distD = (int) dist;
                    
                    if(dist == (int) dist)
                    {
                        count ++;
                    }

                }
            }

            Console.WriteLine(count);

        }
    }
}


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

template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin>>N;
    cout<<"ABC"<<N<<endl;
}


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

#define pb push_back
#define fastio cin.tie(nullptr); ios_base::sync_with_stdio(false)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef long double ld;

template<class T>
struct RangeMax {
    vector<vector<T>> st;
    vi lg;
    RangeMax (int n) : lg(n + 1) {
        for (int i = 2; i <= n; i++) lg[i] = lg[i >> 1] + 1;
        st.assign(lg[n] + 1, vi(n));
    }
    T& at (int i) { return st[0][i]; } // array must be manually read
    void build (int n) {
        for (int j = 1; j <= lg[n]; j++) for (int i = 0; i + (1 << j) <= n; i++)
            st[j][i] = max(st[j - 1][i], st[j - 1][i + (1 << (j - 1))]);
    }
    T query (int l, int r) {        // 0-based indexation, closed intervals
        int k = lg[r - l + 1];
        return max(st[k][l], st[k][r - (1 << k) + 1]);
    }
};

const int N = 5e3 + 10;

vector<RangeMax<int>> st;
ll sub[N];

ll rangeSum (int l, int r) {
    if (r == 0) {
        return 0;
    } else if (l == 0) {
        return sub[r - 1];
    } else {
        return sub[r - 1] - sub[l - 1];
    }
}

ll dp[N];

// TODO cost of taking subarray [l, r] as a block
ll cost (int l, int r) {
    ll ans = -rangeSum(l, r);
    for (auto& it : st) {
        ans += it.query(l, r);
    }
    return ans;
}

void solve (int l, int r, int pl, int pr) {
    if (r < l) return;
    int m = l + r >> 1;
    pair<ll, int> opt;
    // NOTE: objective function is maximized
    opt.first = numeric_limits<ll>::min();
    for (int i = pl; i <= pr; i++) {
        if (i > m) break;
        // NOTE: objective function is maximized
        opt = max(opt, {cost(i, m), i});
    }
    dp[m] = opt.first;
    solve(l, m - 1, pl, opt.second);
    solve(m + 1, r, opt.second, pr);
}

int main () {
    fastio;
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n - 1; i++) cin >> sub[i];
    for (int j = 0; j < m; j++) st.emplace_back(n);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> st[j].at(i);
        }
    }
    for (int j = 0; j < m; j++) st[j].build(n);
    partial_sum(sub, sub + n, sub);
    solve(0, n - 1, 0, n - 1);
    cout << *max_element(dp, dp + n) << '\n';
}

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

//-std=c++11
//#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::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...);
}
#else
#define trace(...)
#endif

#define LL long long
#define FI ios_base::sync_with_stdio(0); cin.tie(NULL);
#define PREC cout << setprecision(10) << fixed;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 9;
const int MX = 1e5 + 5;

int main()
{
	string s;
	cin >> s;
	if(s[s.size()-1] == 's') {
		cout << s << "es" << endl;
	} else {
		cout << s << "s" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3624
n = int(input())
a = list(map(int,input().split()))
Alice = 0
Bob = 0
isAlice = True
for i in range(n):
    tmp = max(a)
    a.remove(tmp)
    if isAlice:
        Alice += tmp
    else:
        Bob += tmp
    isAlice = not(isAlice)
print(Alice-Bob)

Measured memory_bytes: 9112
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < b; ++i)

void solve() {
    string S; cin >> S;
    int K; cin >> K;
    bool all = true;
    rep(i, 1, S.size()) {
        if(S[i - 1] != S[i]) all = false;
    }
    if(all) {
        long long n = S.size() * K;
        cout << n / 2 << '\n';
        return;
    }
    string T = S + S;
    long long cnts = 0;
    rep(i, 1, S.size()) {
        if(S[i - 1] == S[i]) {
            cnts++;
            S[i] = 'A';
            ++i;
        }
    }
    long long cntt = 0;
    rep(i, 1, T.size()) {
        if(T[i - 1] == T[i]) {
            cntt++;
            T[i] = 'A';
            ++i;
        }
    }
    long long ans = 0;
    if(K == 1) ans = cnts;
    else if(K == 2) ans = cntt;
    else {
        long long dif = cntt - cnts;
        ans = cnts + dif * (K - 1);
    }
    cout << ans << '\n';
}

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


Measured memory_bytes: 256
N, W = map(int, input().split(" "))
WV = [list(map(int, input().split(" "))) for _ in range(N)]

dp = [[0 for _ in range(W+1)] for _ in range(N+1)]

for i, (w, v) in enumerate(WV):
    for j in range(W+1):
        if w <= j:
            dp[i+1][j] = max(
                dp[i][j-w] + v,
                dp[i][j]
            )
        else:
            dp[i+1][j] = dp[i][j]

print(dp[N][W])

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

using namespace std;

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

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

string s;
ll a[555555],b[555555],c[555555];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> s;
	int n = s.length();

	for(int i = 0; i < n; i++){
		if(s[i]=='<' && (i==0||s[i-1]=='<'))a[i+1] = a[i]+1;
		else if(s[i]=='<') a[i+1] = 1;
	}
	for(int i = n-1; i >=0; i--){
		if(s[i]=='>' && (i==n-1||s[i+1]=='>'))b[i] = b[i+1]+1;
		else if(s[i]=='>') b[i] = 1;
	}
	ll sum = 0;
	for(int i = 0; i <= n; i++){
		c[i] = max(a[i],b[i]);
		//cout<<a[i]<<' '<<b[i]<<' '<<c[i]<<endl;
		sum += c[i];
	}
	
	cout<<sum;
	
	
	
	return 0;
}



Measured memory_bytes: 13468
n,k,q = [int(x) for x in input().split()]
li = []
for i in range(q):
    a = int(input())
    li.append(a)
score = [k] * (n + 1)
temp =[0]*(n+2)
for pe in li:
    temp[1] += (-1)
    temp[pe] -= (-1)
    temp[pe + 1] += (-1)
    temp[n + 1] -= (-1)

for i in range(1,n + 2):
    temp[i] += temp[i - 1]
#print(temp)
for i in range(1,n + 1):
    score[i] += temp[i]
    if(score[i] <= 0):
        print('No')
    else:
        print('Yes')

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

int main() {
    int n,k;
    cin>>n>>k;
    vector<long long> h(n);
    for(int i=0;i<n;i++) cin>>h.at(i);
    long long p=0;
    sort(h.begin(),h.end());
    for(int i=0;i<n-k;i++) p+=h.at(i);
    cout<<p;
}
    
    

Measured memory_bytes: 1792
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <typeinfo>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T>
// using Tree =
//     tree<T, null_type, less<T>, rb_tree_tag,
//     tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;  // check the limits, dummy

void Main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int N;
  cin >> N;
  // cout << N << '\n';

  vi v;
  vi v1;
  int n;
  F0R(i, N) {
    cin >> n;
    v.push_back(n);
  }
  v1 = v;

  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());

  F0R(i, N) {
    if (v1[i] == v[0]) {
      cout << v[1] << '\n';
    } else {
      cout << v[0] << '\n';
    }
  }
}

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

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

#define REP(A, H) for(int A = 0; A < H; A++)
#define ALL(c) c.begin(), c.end()

int main(void) {
  std::string s; std::cin >> s;
  int max = 0;
  REP(i, s.size()) {
    int cnt = 0;
    REP(j, s.size() - i) 
    {
      char t = s[i + j];
      bool chk = t == 'A' || t == 'C' || t == 'G' || t == 'T';
      if (chk) {
        cnt++;
      } else {
        break;
      }
    }
    max = std::max(max, cnt);
  }

  std::cout << max << std::endl;

  return 0;
}

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

using namespace std;

int main() {
  int N, r;
  cin >> N;
  r = N % 10;
  if (r == 2 || r == 4 || r == 5 || r == 7 || r == 9 ) {
    printf("hon");
  } else if (r == 0 || r == 1 || r == 6 || r == 8) {
    printf("pon");
  } else if (r == 3) {
    printf("bon");
  }
  return 0;
}


Measured memory_bytes: 3656
#include<algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include  <stdio.h>
#include   <math.h>
#include   <time.h>
#include   <vector>
#include   <bitset>
#include    <queue>
#include      <set>
#include      <map>
using namespace std;

const int N=105;

char s[N];

int main()
{
	cin>>s;
	if(s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I')
		puts("Yes");
	else
		puts("No");
	return 0;
}


Measured memory_bytes: 384
N = int(input())
 
X=[]
for i in range(N):
    S, P = input().split()
    X.append([S,int(P)])
 
sort1=sorted(X, key=lambda x:x[1], reverse=True)
sort2=sorted(sort1, key=lambda x:x[0])
 
for j in range(N):
    print(X.index(sort2[j])+1)

Measured memory_bytes: 3060
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            if (S == "ABC")
            {
                Console.WriteLine("ARC");
            }
            else
            {
                Console.WriteLine("ABC");
            }
        }
    }
}

Measured memory_bytes: 25744
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long n, m, x, y, b = 0;
	cin >> n >> m >> x >> y;
	if (x == n / 2.0 && y == m / 2.0) b = 1;
	cout << fixed << setprecision(12) << n * m / (double)2.0 << " " ;cout << b << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.Math;

public class Main{
	public static void main(String args[]){
		call();
	}

	public static void call(){
		Scanner sc = new Scanner(System.in);
		int keta = sc.nextInt();
		int numOfData = sc.nextInt();
      if(keta == 1 && numOfData != 0){
        int key = sc.nextInt();
        int value = sc.nextInt();
        if(key != 1 || numOfData!= 1){
          System.out.println(-1);
          return;
        }else{
          System.out.println(value);
          return;
        }
      }else if(keta == 1 && numOfData == 0){
        System.out.println(0);
        return;
      }
      
    
		Map<Integer,Integer> map = new HashMap<>(numOfData);
		//mapに桁数と値を入れる
		//キーの値が更新されそうになったら、-1を出力して終了する
		for(int i = 0; i < numOfData; i++){
			int key = 0;
			int value = 0;
			key = sc.nextInt();
			value = sc.nextInt();
			if(map.containsKey(key) && map.get(key) != value){
				System.out.println(-1);
				return;
			}
			map.put(key,value);
		}
		//一桁目が0になる指定があれば、-1を出力して終了する
		if(map.containsKey(1) && map.get(1) == 0/*左の条件がfalseならここは検査されない(はず)*/){
			if(keta == 1){
				System.out.println(0);
				return;
			}else{
				System.out.println(-1);
				return;
			}
		}
		//指定された桁に値を代入する
		int ans = 0;
		for(int key: map.keySet()){
			ans += map.get(key) * Math.pow(10, keta - key);
		}
		//答えが指定された桁数より小さければ、桁数を10の累乗を足すことで合わせる
		if(ans < Math.pow(10, keta -1)){
			ans += Math.pow(10, keta -1);
		}
		System.out.println(ans);
		return;
	}
}


Measured memory_bytes: 22996
import sys
sys.setrecursionlimit(100000)
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]
G = [[False]*(N+1) for _ in range(N+1)]

for elem in AB:
    a, b = elem
    G[a][b] = True
    G[b][a] = True

used = [False] * (N+1)


def dfs(v):
    ret = 1
    used[v] = True
    for nv in range(1, N+1):
        if G[v][nv] and not used[nv]:
            ret += dfs(nv)
    return ret


ans = 0
for elem in AB:
    a, b = elem
    G[a][b] = False
    G[b][a] = False
    for j in range(1, N+1):
        used[j] = False
    if dfs(1) != N:
        ans += 1
    G[a][b] = True
    G[b][a] = True
print(ans)


Measured memory_bytes: 3064
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#include<string>
#include<sstream>
#include<stack>
#include<queue>
#include<list>
#include<functional>
#define _USE_MATH_DEFINES

#include<math.h>
#include<map>

#define SENTINEL 1000000001

#define min(a,b) (a)>(b)?(b):(a)
#define max(a,b) (a)>(b)?(a):(b)

using namespace std;

typedef pair<int, int> pii;

int jt[10001];

int main()
{
	map<char, int> mt;
	string T, P;
	cin >> T >> P;

	jt[0] = -1;
	jt[1] = 0;
	int i = 2, j = 0;
	int k = 0;
	while (i <= P.size()) 
	{
		if (P[i - 1] == P[j])
		{
			jt[i] = j + 1;
			++i;
			++j;
		}
		else if (j > 0)
		{
			j = jt[j];
		}
		else
		{
			jt[i++] = 0;
		}
	}
	
	i = j = 0;
	while (i<T.size()) 
	{
		if (T[i] == P[j]) 
		{
			++i;
			++j;
			if (j == P.size()) 
			{
				cout << i - P.size() << '\n';
				j = jt[j];
			}
		}
		else if (j == 0)
		{
			++i;
		}
		else
		{
			j = jt[j];
		}
	}
	return 0;
}


Measured memory_bytes: 3912
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cassert>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <cctype>
#include <iomanip>
#include <sstream>
#include <cctype>
#include <fstream>
#include <cmath>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define ITER(c) __typeof((c).begin())
#define PB(e) push_back(e)
#define FOREACH(i, c) for(ITER(c) i = (c).begin(); i != (c).end(); ++i)
#define MP(a, b) make_pair(a, b)
#define PARITY(n) ((n) & 1)

typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-10;

bool locked;
set<string> registered;

int main(){
  int n, m;
  string str;
  cin >> n;
  locked = true;
  for(int i = 0; i < n; i++){
    cin >> str;
    registered.insert(str);
  }
  cin  >> m;
  for(int j = 0; j < m; j++){
    cin >> str;
    if(registered.count(str) > 0){
      if(locked){
        locked = false;
        cout << "Opened by " << str << endl;
      }else{
        locked = true;
        cout << "Closed by " << str << endl;
      }
    }else{
      cout << "Unknown " << str << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1232
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input! {
    a: usize,
    b: usize
    }
    let mut ans = 0;
    let mut m = 1;
    while m < b {
        ans += 1;
        m += a - 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
n,k = map(int,input().split())
p = list(map(int,input().split()))
lsum = [0]+[p[0]]+[0]*n
for i in range(2,n+1):
  lsum[i] = lsum[i-1] + p[i-1]
ans = 0
flag = 0
for i in range(0,n-k+1):
  if ans < lsum[k+i]-lsum[i]:
    flag = i
    ans = lsum[k+i]-lsum[i]
ans = 0
for i in range(flag,flag+k):
  ans += (p[i]+1)/2
print(ans)

Measured memory_bytes: 24804
from functools import reduce
import fractions


def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)


def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)


def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


n = int(input())
a = list(map(int, input().split()))
l = lcm_list(a)
ans = sum([l // x for x in a]) % int(1e9+7)
print(ans)


Measured memory_bytes: 264668
#!/usr/local/bin/python3

import bisect
import sys

(a, b) = tuple(map(int, input().split(' ')))

if a <= b:
    print("Impossible")
    sys.exit()

n = a + b

def ask(i, j):
    print("? ", i, j)
    ans = input()
    if ans == 'Y':
        return True
    elif ans == 'N':
        return False

path = []
nlen = b + 1
for i in range(n):
    if len(path) == 0:
        path.append(i)
        if len(path) >= nlen:
            break
    else:
        if ask(path[-1], i):
            path.append(i)
            if len(path) >= nlen:
                break
        else:
            path.pop()
            nlen -= 1
    #print(path, nlen)
            
o1 = path[-1]

result = ''
for i in range(n):
    if i != o1:
        if ask(o1, i):
            result += '1'
        else:
            result += '0'            
    else:
        result += '1'        

print('!', result)


Measured memory_bytes: 3532
#include <iostream>
using namespace std;
int main() {
	int N;
	cin >> N;
	if (N % 2 == 0) {
		cout << N / 2 * (N - 2) << endl;
		for (int i = 1; i <= N; i++) {
			for (int j = i + 1; j <= N; j++) {
				if (i + j == N + 1) continue;
				else cout << i << " " << j << endl;
			}
		}
	}
	else {
		cout << ((N - 2) * N + 1) / 2 << endl;
		for (int i = 1; i <= N; i++) {
			for (int j = i + 1; j <= N; j++) {
				if (i + j == N) continue;
				else cout << i << " " << j << endl;
			}
		}
	}
}


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

string s;

int main() {
    cin >> s;
    int count0 = 0, count1 = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '0') count0++;
        else count1++;
    }
    cout << min(count0, count1) * 2 << endl;
    return 0;
}

Measured memory_bytes: 512
#include <string>
#include <utility>
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	string S;

	cin >> S;

	for (string::size_type i = 0; i < S.size() / 2; i++)
	{
		swap(S[i], S[S.size() - i - 1]);
	}

	for (string::size_type i = 0; i < S.size(); i++)
	{
		cout << S[i];
	}

	cout << endl;

	return 0;
}

Measured memory_bytes: 1172
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps=1e-8;
int main() {
	int d, n;
	cin >> d >> n;
	if (n == 100&&d==0) {
		cout << 101 << endl;
	}
	else if (n == 100 && d == 1) {
		cout << 10100 << endl;
	}
	else if (n == 100 && d == 2) {
		cout << 1010000 << endl;
	}
	else {
		cout << (int)n*pow(100, d) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
a,b,k = map(int,input().split())

if (b-a)//2 + 1 <= k:
  for i in range(a,b+1):
    print(i)
else:
  for i in range(a,a+k):
    print(i)
  for j in range(b-k+1,b+1):
    print(j)

Measured memory_bytes: 3060
#include<stdio.h>
#define MAX 100000
main(){
  int p, i;
  int M[MAX+1];
  scanf("%d", &p);
  for ( i = 1; i <= p; i++ ) scanf("%d", &M[i]);

  for (i=1;i<=p;i++) {
    printf("node %d: key = %d, ",i,M[i]);
    if (i/2>=1)printf("parent key = %d, ", M[i/2]);
    if (i*2<=p) printf("left key = %d, ", M[i*2]);
    if (i*2+1<=p) printf("right key = %d, ", M[i*2+1]);
    printf("\n");
  }
  
  return 0;
}



Measured memory_bytes: 2056
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.12f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 1010101;

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// mod.m での a の逆元 a^ { -1 } を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x /gcd(x, y) * y );
}

ll dx[8] = { 1,-1,0,0,1,1,-1,-1 };
ll dy[8] = { 0,0,1,-1,1,-1,1,-1 };
char c[2010][2010];
ll sum[2010][2010];
ll res[10][10];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	string s;
	cin >> s;
	ll res = 0;
	ll res2 = 0;
	rep(i, 4) {
		if (i == 0 || i == 1) {
			if (i == 0)res += 10 * (s[i] - '0');
			else res += 1 * (s[i] - '0');
		}
		else {
			if (i == 2)res2 += 10 * (s[i] - '0');
			else res2 += s[i] - '0';
		}
	}
	if (0 < res && res <= 12 && 0 < res2 && res2 <= 12)puts("AMBIGUOUS");
	else if (0 < res && res <= 12)puts("MMYY");
	else if (0 < res2 && res2 <= 12)puts("YYMM");
	else puts("NA");
	return 0;
}


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


int main(){
  int H,W;
  cin>>H>>W;
  vector<vector<char>> s(H+2,vector<char>(W+2));
  for(int i=1;i<=H;++i){
    for(int j=1;j<=W;++j){
      cin>>s.at(i).at(j);
    }
  }
  
  for(int j=0;j<W+2;++j){
    s.at(0).at(j)='.';
    s.at(H+1).at(j)='.';
  }
  for(int j=0;j<H+2;++j){
      s.at(j).at(0)='.';
      s.at(j).at(W+1)='.';
  }

  bool ans=true;
  for(int i=1;i<=H;++i){
    for(int j=1;j<=W;++j){
      if(s.at(i).at(j)=='#'){
        int count=0;
        for(int k=-1;k<=1;++k){
          for(int l=-1;l<=1;++l){
            if(k*l==0 && s.at(i+k).at(j+l)=='#'){
              ++count;
            }
          }
        }
        if(count==1){
          ans=false;
        }
      }
    }
  }

  if(ans){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}
}

Measured memory_bytes: 256
/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#include <bits/stdc++.h>
using namespace std;

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
#define endl '\n'
#define mem(i,j) memset(i,j,sizeof (i));
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define bit(s,i) (((s)>>(i))&1LL)
#define lowbit(x) ((x)&(-(x)))
#define siz(v) (long long)(v).size()
typedef int64_t ll;
typedef uint64_t ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const ll LINF     = 4611686018427387903;
const int MOD     = 1e9+7;
const int MAXN    = 2e5+9;
/*-----------------------------------------------------------------------------------------------------*/

signed main() {
    EmiliaMyWife

    string s;
    cin >> s;
    int n = s.size();
    reverse(all(s));
    vector<vector<int> > dp(n+1, vector<int>(2));
    dp[0][1]=INF;
    for(int i = 1; i <= n; i++) {
        dp[i][1]=min(dp[i-1][0]+1+(10-s[i-1]+'0'), dp[i-1][1]+(10-s[i-1]+'0')-1);
        dp[i][0]=min(dp[i-1][0], dp[i-1][1])+(s[i-1]-'0');
    }
    cout << min(dp[n][0], dp[n][1]);

	return 0;
}


Measured memory_bytes: 55964