akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

vector<int> ans;

/*
  delta(V v, update(V t))
  index(V v) -> int
*/
template<class V, class Delta, class Index>
vector<ll> bfs(int n, V s, Delta delta, Index index) {
  vector<ll> dist(n,-1);
  queue<V> que;
  dist[index(s)] = 0;
  que.push(s);
  while(!que.empty()) {
    V v = que.front(); que.pop();
    auto update = [&](V t) {
      if (dist[index(t)] == -1) {
        dist[index(t)] = dist[index(v)]+1;
        que.push(t);
        ans[index(t)] = index(v);
      }
    };
    delta(v,update);
  }
  return dist;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n, m;
  cin >> n >> m;
  vector<vector<int> > G(n);
  rep(i,m) {
    int a,b;
    cin >> a >> b;
    a--; b--;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
  }

  auto index = [](int v){ return v;};
  auto delta = [&](int v, auto update) {
    for (auto&& to : G[v]) {
      update(to);
    }
  };
  ans.resize(n);
  auto res = bfs(n, 0, delta, index);
  rep(i,n) {
    if (res[i] == -1) {
      cout << "No\n";
      return 0;
    }
  }
  cout << "Yes\n";
  for(int i = 1; i < n; ++i) {
    cout << ans[i]+1 << "\n";
  }
  return 0;
}

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

int main() {
    int N, Y;
    cin >> N >> Y;
    for (int i = 0; i <= N; i++) {
        for (int j = 0; i + j <= N; j++) {
            int k = N - (i + j);
            int sum = 10000 * i + 5000 * j + 1000 * k;
            if (Y == sum) {
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
}


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

using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,k;
    cin >> n >> k;
    vector<int> h(n);
    for(int i=0;i<n;i++) cin >> h[i];
    vector<int> dp(n,(1<<30));
    dp[0]=0;
    for(int i=1;i<n;i++)
    {
        for(int j=1;j<=k&&i-j>=0;j++) dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
    }
    cout << dp[n-1] << "\n";
    return 0;
}


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

#define ll long long 
#define ff(i, a, b) for(int i = a; i <= b; i++)
#define fo(i, a, b) for(int i = a; i < b; i++)
#define fod(i, a, b) for(int i = a; i >= b; i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

const int INF = 1e9, N = 510, M = 20001;
const ll INFL = 1e18;

typedef pair <int, int> ii;
typedef vector <int> vi;
typedef vector <ii> vii;

int n, m;
ll f[N][M], s[M]; 
int p[M], c[N], e[N];
ll ans;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> m >> n; ff(i, 1, m) cin >> p[i];
	ff(i, 1, n) cin >> c[i] >> e[i];
	m += 10000;
	sort(p + 1, p + m + 1, greater<int>());
	ff(i, 1, m) s[i] = s[i - 1] + p[i];
	//ff(i, 1, m) cout << p[i] << ' ' << s[i] << "\n";
	ff(i, 0, n) ff(j, 0, m) f[i][j] = 0;
	f[0][0] = 0;
	ff(i, 1, n) ff(j, 1, m) {
		f[i][j] = max(f[i][j], f[i - 1][j]);
		if (j >= c[i]) f[i][j] = max(f[i][j], f[i - 1][j - c[i]] + s[j] - s[j - c[i]] - e[i]);
	}
	ff(i, 0, n) ff(j, 0, m) ans = max(f[i][j], ans);
	printf("%lld\n", ans);
}

Measured memory_bytes: 81092
from itertools import accumulate
import sys

def main():
  read = sys.stdin.buffer.read
  N, K, *p = map(int, read().split())
  p = [0] + list(accumulate(p))
  print((max(y - x for x, y in zip(p, p[K:])) + K) / 2)

if __name__ == '__main__':
    main()


Measured memory_bytes: 21140
n = int(input())
a=[]
for i in range(n):
  a.append(int(input()))
#print(a)
aa = sorted(a, reverse=True) 
#print(aa)
m = aa[0]
for i in range(n):
  if a[i] == m:
    print(aa[1])
  else:
    print(m)

Measured memory_bytes: 70104
using System;
using System.Collections.Generic;
using System.Linq;

public class Hello
{
    private const int MOD_N = 1000000000 + 7;

    public static void Main()
    {
        var list = Console.ReadLine().Split(' ');
        var n = int.Parse(list[0]);
        var m = int.Parse(list[1]);

        var ss = new int[m][];
        for (int i = 0; i < ss.Length; ++i)
        {
            var list2 = Console.ReadLine().Split(' ');
            var k = int.Parse(list2[0]);
            var s = new int[k];
            for (int j = 0; j < s.Length; ++j)
                s[j] = int.Parse(list2[j + 1]) - 1;
            ss[i] = s;
        }

        var list3 = Console.ReadLine().Split(' ');
        var ps = new int[m];
        for (int i = 0; i < ps.Length; ++i)
            ps[i] = int.Parse(list3[i]);

        int ans = 0;

        var states = new bool[n + 1];
        for (int i = 0; true; ++i)
        {
            int t = 1;
            for (int j = 0; j < states.Length; ++j)
            {
                states[j] = (i & t) > 0;
                t <<= 1;
            }
            if (states[n])
                break;

            for (int j = 0; j < ss.Length; ++j)
            {
                var s = ss[j];
                int total = 0;
                for (int k = 0; k < s.Length; ++k)
                {
                    if (states[s[k]])
                        ++total;
                }
                if ((total % 2) != ps[j])
                {
                    goto Next;
                }
            }
            ++ans;
            Next:
            ;
        }

        Console.WriteLine(ans);
    }

    private static int Comb(int m, int n)
    {
        var t = m - n;
        if (n > t)
            n = t;

        long numerator = 1;
        for (int i = 0; i < n; ++i)
        {
            numerator *= m - i;
            numerator %= MOD_N;
        }
        long denominator = 1;
        for (; n != 0; --n)
        {
            denominator *= n;
            denominator %= MOD_N;
        }

        var inv_denominator = ModInv((int)denominator, MOD_N);
        var ret = (int)(numerator * inv_denominator % MOD_N);

        return ret >= 0 ? ret : ret + MOD_N;
    }

    private static int ModInv(int a, int m)
    {
        int b = m, x = 1, y = 0;
        while (b != 0)
        {
            var t = a / b;
            a -= t * b;
            Swap(ref a, ref b);
            x -= t * y;
            Swap(ref x, ref y);
        }
        x %= m;
        return x >= 0 ? x : x + m;
    }

    private static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
}


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

struct P {
  int x, y;
  P(int x, int y) : x(x), y(y) { }
};

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

int main() {
  for(int W, H; cin >> W >> H && W; ) {
    vector<string> M;
    queue<P> que;

    for(int y = 0; y < H; y++) {
      string line;
      cin >> line;

      M.push_back(line);

      for(int x = 0; x < W; x++) {
        if(M[y][x] == '@') {
          que.push(P(x, y));
        }
      }
    }

    int answer = 0;
    for(; !que.empty(); que.pop()) {
      P p = que.front();
      answer++;

      for(int i = 0; i < 4; i++) {
        int nx = p.x + dx[i], ny = p.y + dy[i];

        if(0 <= nx && nx < W && 0 <= ny && ny < H && M[ny][nx] == '.') {
          M[ny][nx] = '#';
          que.push(P(nx, ny));
        }
      }
    }

    cout << answer << endl;
  }
}

Measured memory_bytes: 3032
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;
 
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(void)
{
    ll n, k;
    cin >> n >> k;
    vector<ll> h(n);
    REP(i,n){
        cin >> h[i];
    }
    sort(all(h));

    ll ans = 0;
    REP(i,n-k){
        ans += h[i];
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

typedef short sho;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;
typedef string str; 
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll; 
typedef pair<ld,ld> pld;
 
typedef vector<int> vi; 
typedef vector<ll> vl; 
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<pld> vpd;

#define LOCAL
#define MP make_pair 
#define FF first
#define SS second
#define sz(x) (int)x.size()
#define begin(x) (x).begin() 
#define end(x) (x).end()
#define rbegin(x) (x).rbegin()
#define rend(x) (x).rend()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define PF push_front 
#define PB push_back
#define PP push
#define lb lower_bound 
#define ub upper_bound
#define lowbit(x) x&(-x)
#define testbit(x,i) x&(1<<i)

inline void checkmin(int &x,int y){x=min(x,y);}
inline void checkmax(int &x,int y){x=max(x,y);}

int N;
string S;

set<string> st;

int main() 
{
	#ifndef LOCAL
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /* start code */
    cin>>N;
    while(N--)
    {
    	cin>>S;
		st.insert(S); 
	}
	cout<<st.size()<<endl;
    /* end code */
	return 0;
}

Measured memory_bytes: 19236
A,B,K= list(map(int, input().split()))
l = []
if(A<K):
    l.append(0)
    l.append(A-K+B)
    if(l[1]<0):
        l[1]=0
else:
    l.append(A-K)
    l.append(B)
print(l[0],l[1])

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int n,a[225816];
stack<P> s;

bool addone(int p, int k){
	int v;
	if(p<1){
		return false;
	}
	while((!s.empty()) && s.top().first>p){
		s.pop();
	}
	if(s.empty()){
		s.push(P(p,1));
		return true;
	}
	if(s.top().first<p){
		s.push(P(p,1));
		return true;
	}
	v = s.top().second; ++v;
	if(v<k){
		s.pop();
		s.push(P(p,v));
		return true;
	}else{
		return addone(p-1,k);
	}
}

bool judge(int k){
	int i,p=0,m=n;
	if(k==0){
		return false;
	}else if(k==1){
		for(i=1; i<n; ++i){
			if(a[i-1]<a[i]){
				continue;
			}
			return false;
		}
		return true;
	}
	for(i=1; i<n; ++i){
		if(a[i-1]<a[i]){
			continue;
		}
		if(!addone(a[i],k)){
			return false;
		}
	}
	return true;
}

int main(void){
	int i,l,r,m;
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> a[i];
	}
	l = 0; r = n;
	while(r-l>1){
		m = (l+r)/2;
		while(!s.empty()){
			s.pop();
		}
		if(judge(m)){
			r = m;
		}else{
			l = m;
		}
	}
	cout << r << endl;
	return 0;
}


Measured memory_bytes: 1024
import heapq
N, M = [int(_) for _ in input().split()]
A = [-int(_) for _ in input().split()]

heapq.heapify(A)

for _ in range(M):
    a = heapq.heappop(A)
    heapq.heappush(A, -(-a//2))

print(-sum(A))

Measured memory_bytes: 14180
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    if(m==100)
        m=101;
    switch(n){
        case 0:{
            cout<<m;
            break;
 
        }
        case 1:{
            cout<<m*100;
            break;
        }
        case 2:{
            cout<<m*10000;
            break;
        }
    }
}

Measured memory_bytes: 384
import itertools
n=int(input())
d=[list(map(int,input().split())) for i in range(n)]

sosuu=[1 for i in range(10**5+1)]
#sosuuのindexの値が1の時素数とする。
sosuu[0]=0
sosuu[1]=0
for i in range(2,10**5+1):
  if sosuu[i]==0:continue
  elif sosuu[i]==1:
    for j in range(2*i,10**5+1,i):
      sosuu[j]=0
like_n=[]
like_n+=sosuu
#奇数なので、2を削除。
like_n[2]=0
for i in range(3,10**5+1):
  if sosuu[i]==0:continue
  elif sosuu[i]==1 and sosuu[(i+1)//2]==0:
    like_n[i]=0
ans= list(itertools.accumulate(like_n))
for ans_d in d:
  print(ans[ans_d[1]]-ans[ans_d[0]-1])



Measured memory_bytes: 32788
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <stack>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 28)
template<typename T>
void remove(vector<T>& vector, unsigned int index){
vector.erase(vector.begin() + index);
}
vector<string> split(const string &s, char c);
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main(void){
    int a,b,c;
    cin >> a >> b >> c;
    if(a-b == 0){
        cout << c << endl;
    }else if(a-c == 0){
        cout << b << endl;
    }else{
        cout << a << endl;
    }

    return 0;
}

int StrToInt(string s){
    stringstream ss;
    ss << s;
    int val;
    ss >> val;
    return val;
}
string IntToStr(int i){
    stringstream ss;
    ss << i;
    return ss.str();
}

vector<string> split(const string &s, char delim) {
    vector<string> elems;
    string item;
    for (int i = 0; i < s.size(); i++) {
        char ch = s[i];
        if (ch == delim) {
            if (!item.empty())
                elems.push_back(item);
            item.clear();
        }
        else {
            item += ch;
        }
    }
    if (!item.empty())
        elems.push_back(item);
    return elems;
}


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

int main(){
	int x,y;
  	cin>>x>>y;
  	
  	if(x==y){
     	cout<<"Draw"<<endl; 
      	return 0;
    }
  
  	if(x==1) x=14;
  	if(y==1) y=14;
       
  	
  	if(x>y){
     	cout<<"Alice"<<endl; 
    }else{
     	cout<<"Bob"<<endl; 
    }  
}    

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

#include <bits/stdc++.h>
using namespace std;

int main() {
  ll h;
  cin>>h;
  
  ll x=1;
  ll sum=1;
  while(h>1){
    h/=2;
    x*=2;
    sum+=x;
  }
  
  cout<<sum<<endl;
  
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = str(input())
B = str(input())
C = str(input())
ans = 0
for i in range(0, N):
    tmp = set()
    tmp.add(A[i])
    tmp.add(B[i])
    tmp.add(C[i])
    ans += (len(tmp)-1)
print(ans)


Measured memory_bytes: 3060
import re
S=input()
if re.fullmatch(r"[a-z]*keyence",S)==None and re.fullmatch(r"k[a-z]*eyence",S)==None and re.fullmatch(r"ke[a-z]*yence",S)==None and re.fullmatch(r"key[a-z]*ence",S)==None and re.fullmatch(r"keye[a-z]*nce",S)==None and re.fullmatch(r"keyen[a-z]*ce",S)==None and re.fullmatch(r"keyenc[a-z]*e",S)==None and re.fullmatch(r"keyence[a-z]*",S)==None:
  print("NO")
else:
  print("YES")

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

int main(){
    ll N;cin>>N;
    for(ll n = 1;n <= N;n++){
        int res = 0;
        for(ll x = 1;x*x < n;x++){
            for(ll y = 1;y * y < n;y++){
                ll ok = 0;
                ll ng = n;
                while(ng - ok > 1){
                    ll z = (ok+ng)/2;
                    if(y*z+z*x+z*z > n - x*x - y*y - x*y){
                        ng = z;
                    }else{
                        ok = z;
                    }
                }
                if(ok == 0)continue;
                if(x*x+y*y+ok*ok+x*y+y*ok+ok*x == n)res++;
            }
        }
        cout<<res<<endl;
        // cout<<n<<"----"<<endl;
    }
}

Measured memory_bytes: 3568
#include <vector>
#include <queue>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <set>
#include <queue>

using namespace std;

int n;
int a[5555], b[5555], ans[5555];
int sa[5555];
int r[5555];

int calc(int l) {
  int res = 0;
  int idx = l - 1;
  int dame = l > 0 ? a[l - 1] : -2;
  /*
  printf("--- l = %d %d -----\n", l, dame);
  for (int i = 0; i < n; i++) printf("%d ", sa[i]); puts("");
  for (int i = 0; i < n; i++) printf("%d ", b[i]); puts("");
  //*/
  for (int i = max(0, l - 1); i < n; i++) {
    if (sa[i] == dame) { dame = -2; continue; }
    while (idx < n && (b[idx] == -1 || sa[i] >= b[idx])) {
      ++idx;
    }
    if (idx >= n) break;
    // printf("i = %d idx = %d\n", i, idx);
    ++idx;
    res += 1;
  }
  // printf("ret = %d\n", res);
  return res;
}

int main(void) {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", a+i);
    sa[i] = a[i];
  }
  sort(sa, sa+n);
  for (int i = 0; i < n; i++) scanf("%d", b+i);
  sort(b, b+n);
  int res = calc(0);
  // printf("res = %d\n", res);

  int cur = 0;
  for (int i = 0; i < n; i++) {
    // printf("%d\n", i);
    if (b[n - 1] <= a[i]) {
      int lb, rb;
      lb = i;
      rb = n;
      while (rb - lb > 1) {
        int mb = (lb + rb) / 2;
        int c = b[mb];
        int t = 0, tmp = -1;
        if (b[mb] > a[i]) t = 1;
        swap(b[mb], tmp);
        if (cur + t + calc(i + 1) == res) {
          lb = mb;
        } else {
          rb = mb;
        }
        swap(b[mb], tmp);
      }
      if (b[lb] > a[i]) cur += 1;
      ans[i] = b[lb];
      b[lb] = -1;
      while (--lb >= i) swap(b[lb + 1], b[lb]);
    } else {
      int lb, rb;
      lb = i;
      while (lb < n && b[lb] <= a[i]) ++lb;
      rb = n;
      while (rb - lb > 1) {
        int mb = (lb + rb) / 2;
        int c = b[mb];
        int t = 0, tmp = -1;
        if (b[mb] > a[i]) t = 1;
        swap(b[mb], tmp);
        // printf("%d %d %d\n", cur, t, calc(i + 1));
        if (cur + t + calc(i + 1) == res) {
          lb = mb;
        } else {
          rb = mb;
        }
        swap(b[mb], tmp);
      }
      if (b[lb] > a[i]) cur += 1;
      ans[i] = b[lb];
      b[lb] = -1;
      while (--lb >= i) swap(b[lb + 1], b[lb]);
    }

    // printf("remove = %d\n", a[i]);
    for (int j = 0; j < n; j++) {
      if (sa[j] == a[i]) {
        sa[j] = -1;
        while(--j >= i) swap(sa[j], sa[j+1]);
        break;
      }
    }
    /*
    for (int j = 0; j < n; j++) printf("%d ", b[j]);
    puts("");
    for (int j = 0; j < n; j++) printf("%d ", sa[j]);
    puts("");
    */
  }

  for (int i = 0; i < n; i++) {
    printf("%d%c", ans[i], i + 1 == n ? '\n' : ' ');
  }
  // printf("%d\n", res);
  return 0;
}




Measured memory_bytes: 2892
use std::collections::VecDeque;

fn main() {
    let mut sc = Scanner::new();
    let n = sc.read::<usize>();
    let m = sc.read::<usize>();

    let mut odd = VecDeque::new();
    let mut even = VecDeque::new();

    for _ in 0..m {
        let a = sc.read::<usize>();
        if a % 2 == 0 {
            even.push_back(a);
        } else {
            odd.push_back(a);
        }
    }

    if odd.len() > 2 {
        println!("Impossible");
        return;
    }

    let mut ans_a = Vec::new();
    let mut ans_b = Vec::new();

    if !odd.is_empty() {
        let p = odd.pop_front().unwrap();
        ans_a.push(p);
        if p > 1 {
            ans_b.push(p - 1);
        }
    } else {
        let p = even.pop_front().unwrap();
        ans_a.push(p);
        ans_b.push(p - 1);
    }

    while !even.is_empty() {
        let p = even.pop_front().unwrap();
        ans_a.push(p);
        ans_b.push(p);
    }

    if !odd.is_empty() {
        let p = odd.pop_front().unwrap();
        ans_a.push(p);
        ans_b.push(p + 1);
    } else {
        ans_b.push(1);
    }

    for i in 0..ans_a.len() {
        if i > 0 {
            print!(" ");
        }
        print!("{}", ans_a[i]);
    }
    println!();
    println!("{}", ans_b.len());
    for i in 0..ans_b.len() {
        if i > 0 {
            print!(" ");
        }
        print!("{}", ans_b[i]);
    }
    println!();
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner { ptr: 0, length: 0, buf: vec![0; 1024], small_cache: vec![0; 1024] }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool { b == b'\n' || b == b'\r' || b == b'\t' || b == b' ' }

    fn read<T>(&mut self) -> T where T: std::str::FromStr, T::Err: std::fmt::Debug, {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)]).parse().unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}



Measured memory_bytes: 4352
#include <cstdio>
#define N 55
#define ll long long 
int n,P,a[N];
ll f[N][2];
int main(){
	scanf("%d%d",&n,&P);
	for(int i=1;i<=n;++i) scanf("%d",&a[i]),a[i]%=2;
	f[0][0]=1;
	for(int i=1;i<=n;++i){
		if(a[i]){
			f[i][0]=f[i-1][1]+f[i-1][0];
			f[i][1]=f[i-1][1]+f[i-1][0];
		}else{
			f[i][0]=f[i-1][0]*2;
			f[i][1]=f[i-1][1]*2;
		}
	}
	printf("%lld\n",f[n][P]);
	return 0;
}

Measured memory_bytes: 128
using System;

namespace answer
{
    class Program
    {
        static void Main(string[] args)
        {
            var first = int.Parse(Console.ReadLine());
            int kotae = 0;
            int gohyaku = 0;
            int go = 0;

            while (true)
            {
                if (first < 500)
                {
                    break;
                }
                gohyaku++;
                first = first - 500;
            }
            gohyaku = gohyaku * 1000;

            while (true)
            {
                if (first < 5)
                {
                    break;
                }
                go++;
                first = first - 5;
            }
            go = go * 5;
            kotae = gohyaku + go;
            Console.WriteLine(kotae.ToString());
        }
    }
}

Measured memory_bytes: 13140
#include<iostream>
#include<cmath>
#include<vector>

using namespace::std;

int main(){
  int n;
  cin >> n;
  n %= 10;
  if(n == 1 || n == 6 || n == 8 || n == 0){
    cout << "pon" << endl;
  } else if(n == 3){
    cout << "bon" << endl;
  } else {
    cout << "hon" << endl;
  }
  return 0; 
}

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

int main() {
  int N, X, T, kaisu;

  // 標準入力から読み込み
  cin >> N >> X >> T;
  
  // たこ焼きを焼く回数を求める
  kaisu = N / X;
  if (N % X != 0)
    kaisu++;
  
  // かかる時間を出力
  cout << T * kaisu << endl;
  
  return 0;
}

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

const int TARGET = 7;
int a, b, c, d;

// each op represents '+' if 1; '-' if 0
inline bool eval(int op1, int op2, int op3)
{
  if (op1 && op2 && op3) return a+b+c+d == TARGET;
  if (op1 && op2 && !op3) return a+b+c-d == TARGET;
  if (op1 && !op2 && op3) return a+b-c+d == TARGET;
  if (op1 && !op2 && !op3) return a+b-c-d == TARGET;
  if (!op1 && op2 && op3) return a-b+c+d == TARGET;
  if (!op1 && op2 && !op3) return a-b+c-d == TARGET;
  if (!op1 && !op2 && op3) return a-b-c+d == TARGET;
  if (!op1 && !op2 && !op3) return a-b-c-d == TARGET;

  std::cout << "Unknown operations: " << op1 << op2 << op3 << std::endl;

  return false;
}

std::string gen(int op1, int op2, int op3)
{
  std::string ret = std::to_string(a);
  if (op1) ret += '+'; else ret += '-';
  ret += std::to_string(b);
  if (op2) ret += '+'; else ret += '-';
  ret += std::to_string(c);
  if (op3) ret += '+'; else ret += '-';
  ret += std::to_string(d);
  ret += "=7";

  return ret;
}

int main()
{
  std::string s;
  std::cin >> s;
  a = s[0] - '0';
  b = s[1] - '0';
  c = s[2] - '0';
  d = s[3] - '0';

  /*
  std::cout << a << b << c << d << std::endl;
  std::cout << eval(1, 1, 1) << std::endl;
  std::cout << a+b+c+d << std::endl;
  */

  for (int i=0; i<2; i++) {
    for (int j=0; j<2; j++) {
      for (int k=0; k<2; k++) {
        if (eval(i, j, k)) {
          std::cout << gen(i, j, k);
          return 0;
        }
      }
    }
  }

  return 0;
}


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

void func_d(int N) {
	int* A = new int[N];
	int* B = new int[N];
	int cnt = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		B[i] = 0;
	}


	for (int i = N-1; i>=0 ; i--) {
		int value = 0;
		for (int j = i; j < N; j += (i + 1)) {
			value += B[j];
		}
		if (value % 2!=A[i]) {
			B[i] = 1;
			cnt += 1;
		}
	}

	if (cnt % 2 != A[0]) {
		cout << -1;
	}
	else{
		cout << cnt << endl;
		for (int i = 0; i < N; i++) {
			if (B[i]) {
				cout << i + 1 << " ";
			}
		}
	}
	free(A);
	free(B);
}

int main()
{
	int N;
	cin >> N;
	func_d(N);
}

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

int a[1000005], f[1000005];

int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; ++i) {
	    char c;
	    cin >> c;
	    a[i] = c - '1';
	}

	f[0] = 0;
	for (int i = 0; i < N; ++i) f[i + 1] = __builtin_ctz(i + 1) + f[i];

	int ans = 0;
	for (int i = 0; i < N; ++i) {
		ans += a[i] * (f[N - 1] == f[i] + f[N - i - 1]);
	}
	if (ans % 2) {
		cout << 1 << '\n';
		return 0;
	}
	for (int i = 0; i < N; ++i) {
		if (a[i] == 1) {
			cout << 0 << '\n';
			return 0;
		}	
	}
	ans = 0;
	for (int i = 0; i < N; ++i) {
		ans += (a[i] / 2) * (f[N - 1] == f[i] + f[N - i - 1]);
	}
	cout << 2 * (ans % 2) << '\n';
}

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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	
	if(a > b) {
		swap(a, b);
	}
	if(b > c) {
		swap(b, c);
	}
	
	if(a > b) {
		swap(a, b);
	}

	cout << a << " " << b << " " << c << endl;
}


Measured memory_bytes: 3116
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T &a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T &a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------

signed main() {
	int x, y = 1;
	while (cin >> x>>y && x+y) {
		cout << min(x, y) << " " << max(x, y) << endl;
	}
}


Measured memory_bytes: 2992
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int r, c;

int f(int x, int y){
    if(y==0)return x;
    if(x==r)return x+y;
    if(y==c)return r+c+r-x;
    if(x==0)return r+r+c+c-y;
    return r+r+c+c;
}

int main(void){
    int n, m, q[100000];
    vector<P> p;
    vector<int> v;
    cin>>r>>c>>n;
    for(int i=0;i<n;i++){
        int x,y,z,w;
        cin>>x>>y>>z>>w;
        if(x>0&&x<r&&y>0&&y<c)continue;
        if(z>0&&z<r&&w>0&&w<c)continue;
        p.push_back(P(f(x, y), i));
        p.push_back(P(f(z, w), i));
    }
    m=p.size();
    if(m<=2){
        cout<<"YES"<<endl;
        return 0;
    }
    sort(p.begin(), p.end());
    fill(q, q+n, 0);
    for(int i=0;i<m;i++){
        int s=p[i].second;
        q[s]++;
        if(q[s]==2){
            if(v.size()>0){
                int t=v.back();
                if(t==s){
                    v.pop_back();
                    continue;
                }
            }
            cout<<"NO"<<endl;
            return 0;
        }
        v.push_back(s);
    }
    cout<<"YES"<<endl;
}


Measured memory_bytes: 2672
#include <bits/stdc++.h>
 
using namespace std;
 
const long long MOD=1e9+7;
const double PI=3.14159265359;




int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,p;
    cin>>n>>p;
    
    vector<vector<long long>> nCr(n+1,vector<long long>(n+1,0));
        nCr[0][0]=1;
        for(int i=0; i<=n; i++){
            nCr[i][0]=1;
        }
        
        for(int i=1; i<=n; i++){
            for(int j=1; j<=i; j++){
                nCr[i][j]=nCr[i-1][j-1]+nCr[i-1][j];
                
                //cout<<i<<" "<<j<<":"<<mCr[i][j]<<" ";
            }
            
        }
        
    int oct=0, ect=0;
    
    
    for(int i=0; i<n; i++){
        int x;
        cin>>x;
        if(x%2) oct++;
        else ect++;
    }
    //cout<<oct<<endl;
    
    long long ans=0;
    long long eProd=1ll<<ect, oProd=0;
    
    if(p){
        for(int i=1; i<=oct; i+=2){
            oProd+=nCr[oct][i];
        }
    }
    else{
        for(int i=0; i<=oct; i+=2){
            oProd+=nCr[oct][i];
        }
    }
    
    //cout<<eProd<<" "<<oProd<<endl;
    
    ans=oProd*eProd;
    cout<<ans;
    
    
    
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    ArrayList<Integer> list = new ArrayList<Integer>();
    int[] a = new int[m];
    for(int i = 0; i < m; i++) {
      a[i] = sc.nextInt();
      list.add(a[i]);
    }
    long MOD = (long)Math.pow(10, 9) + 7;
    long[] dp = new long[n + 1];
    dp[0] = 1;
    if(list.contains(1)) {
      dp[1] = 0;
    } else {
      dp[1] = 1;
    }
    for(int i = 0; i < m; i++) {
      dp[a[i]] = -1;
    }
    for(int i = 2; i < n + 1; i++) {
      if(dp[i] != -1) {
        long c = 0;
        long d = 0;
        if(dp[i - 1] != -1) c = dp[i - 1];
        if(dp[i - 2] != -1) d = dp[i - 2];
        dp[i] = (c + d) % MOD;
      }
    }
    System.out.println(dp[n]);
  }
}

Measured memory_bytes: 61168
from bisect import bisect_left, insort_left

S = list(input())

alpha = [chr(i) for i in range(ord("a"), ord("a") + 26)]

not_used = list(set(alpha) - set(S))
not_used.sort()

if not not_used:
    can = []
    flag = True
    for i in range(len(S)-1, -1 , -1):
        idx = bisect_left(can, S[i])
        if idx == len(can):
            insort_left(can, S[i])
        else:
            S[i] = can[idx]
            idx = i
            flag = False
            break
    if flag:
        print(-1)
    else:
        print(*S[:idx+1], sep="")
else:
    S.append(not_used[0])
    print(*S, sep="")

Measured memory_bytes: 3064
def main():
    N, K, S = map(int, input().split())

    dummy = 10**9 - 1 if S == 10**9 else 10**9

    ans = []
    for _ in range(K):
        ans.append(str(S))

    for _ in range(N - K):
        ans.append(str(dummy))

    print(" ".join(ans))


main()


Measured memory_bytes: 13464
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define lb(s,x) (lower_bound(all(s),x)-s.begin())
#define ub(s,x) (upper_bound(all(s),x)-s.begin())
#define uniq(a) a.erase(unique(all(a)),a.end())
#define bit(k) (1LL<<(k))
const int INF = 1e9;

#define debug(x) cerr<<(#x)<<": "<<(x)<<endl
template<class T,class U>
ostream& operator<<(ostream& o, const pair<T,U> &p){
    o<<"("<<p.first<<", "<<p.second<<")";
    return o;
}
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }

int h[110];

int calc(int l, int r) {
    if (l == r) return 0;
    while(h[l]==0 && l<r) l++;
    if (l == r) return 0;
    int m = l;
    while(h[m]>0) m++;

    int mn = 1000;
    for (int i = l; i < m; i++) {
        mn = min(mn, h[i]);
    }
    for (int i = l; i < m; i++) {
        h[i] -= mn;
    }
    
    return mn + calc(l,m) + calc(m,r);
}

int main(void){
    int n;
    cin >> n;
    rep(i,n) cin >> h[i];
    cout << calc(0,n) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lli long long int
#define mod 1000000007
#define pb push_back
#define pf push_front
#define ulli unsigned long long int
#define what_is(x) cerr << #x << " is " << x << endl;
#define pi 2*acos(0.0)
#define F  first
#define S  second
#define endl '\n'
#define all(x) x.begin(),x.end()
using namespace std;
const lli INF = 1e18L+5;
/*ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}*/
int main()
{
//cout.precision(9);
//cout.setf(ios::fixed,ios::floatfield);
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
	lli T=1;
    //cin>>T;
	while(T--)
	{
		lli a,b;
		cin>>a>>b;
		if((a+b)%2==0)
		cout<<(a+b)/2<<endl;
		else
		cout<<"IMPOSSIBLE"<<endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

int f[33][33];
int d[4][33][33];

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

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int w,h;
	while(cin >> w >> h,w){
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				cin >> f[i][j];
			}
		}
		int cost[4];
		for(int i=0;i<4;i++){
			cin >> cost[i];
		}
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				for(int k=0;k<4;k++){
					d[k][i][j]=1e9;
				}
			}
		}
		d[0][0][0]=0;
		priority_queue<pair<pair<int,int>,pair<int,int>>> q;
		q.push(make_pair(make_pair(0,0),make_pair(0,0)));
		while(q.size()){
			auto p=q.top(); q.pop();
			if(d[p.first.second][p.second.first][p.second.second]!=-p.first.first)continue;
			int x=p.second.first,y=p.second.second;
			int ho=p.first.second;
			if(f[x][y]!=4){
				int nho=(ho+f[x][y])%4;
				int nx=x+dx[nho] , ny=y+dy[nho];
				if(0<=nx&&nx<h&&0<=ny&&ny<w&&d[nho][nx][ny]>d[ho][x][y]){
					d[nho][nx][ny]=d[ho][x][y];
					q.push(make_pair(make_pair(-d[nho][nx][ny],nho),make_pair(nx,ny)));
				}
			}
			for(int i=0;i<4;i++){
				int nho=(ho+i)%4;
				int nx=x+dx[nho] , ny=y+dy[nho];
				if(0<=nx&&nx<h&&0<=ny&&ny<w&&d[nho][nx][ny]>d[ho][x][y]+cost[i]){
					d[nho][nx][ny]=d[ho][x][y]+cost[i];
					q.push(make_pair(make_pair(-d[nho][nx][ny],nho),make_pair(nx,ny)));
				}
			}
		}
		printf("%d\n",min({d[0][h-1][w-1],d[1][h-1][w-1],d[2][h-1][w-1],d[3][h-1][w-1]}));
	}
}


Measured memory_bytes: 3228
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>
#include <list>
#include <random>

// macros
#define ll unsigned long long int
#define pb emplace_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 60;
const double EPS = 1e-10;
const int mod = 1e9 + 7;

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

ll add(int i){
  if(i == 1)return 5;
  else return (2 * i + 1);
}

int main(int argc, char const* argv[])
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  ll X;
  cin >> n >> X;
  vector<ll> x(n), xsum(n, 0);
  rep(i, n)cin >> x[i];
  reverse(all(x));
  rep(i, n){
    xsum[i] = x[i];
    if(i > 0)xsum[i] += xsum[i-1];
  }
  ll res = linf;
  for(int k = 1; k <= n; k++){
    ll tmp = (ll)(n + k) * X;
    for(int i = 0; i < n; i += k){
      tmp += add(i / k + 1) * (xsum[min(i+k-1, n-1)] - (i > 0 ? xsum[i-1]: 0));
    }
    res = min(res, tmp);
  }
  cout << res << endl;
	return 0;
}


Measured memory_bytes: 3456
#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <numeric>

using namespace std;

int main() {
	string s;
	cin>>s;
	string t;
	cin>>t;
	bool possible=false;
	for(int i1=s.size()-t.size();i1>=0;i1--){
		possible=true;
		for(int i2=0;i2<t.size();i2++){
			if(s.at(i1+i2)=='?'||s.at(i1+i2)==t.at(i2)){

			}else{
				possible=false;
			}
		}
		if(possible){
			for(int i2=0;i2<s.size();i2++){
				if(i2<i1||i2>=i1+t.size()){
					if(s.at(i2)=='?'){
						cout<<"a";
					}else{
						cout<<s.at(i2);
					}
				}else{
					cout<<t.at(i2-i1);
				}
			}
			cout<<endl;
			break;
		}

	}
	if(!possible){
		cout<<"UNRESTORABLE"<<endl;
	}

}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}

int main(){
	ll x,a,b;
	scanf("%lld%lld%lld",&x,&a,&b);
	if(b<=a)puts("delicious");
	else if(b<=a+x)puts("safe");
	else puts("dangerous");
}

Measured memory_bytes: 128
import collections
def main():
    n = int(input())
    d = list(map(int,input().split()))
    m = int(input())
    t = list(map(int,input().split()))

    if n < m:
        print('NO')
        return

    cnt_d = collections.Counter(d)
    cnt_t = collections.Counter(t)

    for i, k in enumerate(cnt_t.keys()):
        if cnt_d[k] >= cnt_t[k]:
            continue
        else:
            print('NO')
            return
    print('YES')


if __name__ == '__main__':
    main()


Measured memory_bytes: 57048
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 9999999999;
const int INFI=2147483647;
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
  T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }


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



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

long long COM = 998244353;

int main() {

  int N, K;
  scanf("%d %d", &N, &K);

  vector<int> L(K);
  vector<int> R(K);

  for (int i=0;i<K;i++){
    scanf("%d %d", &L[i], &R[i]);
  }

  vector<int> v(2*N+1);
  v[1] = 1;
  v[2] = -1;

  for (int i=1;i<N;i++){
    for (int j=0;j<K;j++){
      v[i+L[j]]+=v[i];
      v[i+L[j]]%=COM;
      v[i+R[j]+1]-=v[i];
      v[i+L[j]+1]+=COM;
      v[i+L[j]+1]%=COM;
    }

    v[i+1]+=v[i];
    v[i+1]%=COM;
  }

  printf("%d\n", v[N]);

  
  return 0;
}




Measured memory_bytes: 4844
N,M = map(int,input().split())
A,B,C,D = [],[],[],[]
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
for i in range(M):
    c,d = map(int,input().split())
    C.append(c)
    D.append(d)

Ans = []
for i in range(N):
    d = 10**9
    for j in range(M):
        if d > abs(A[i]-C[j])+abs(B[i]-D[j]):
            d = abs(A[i]-C[j])+abs(B[i]-D[j])
            ans = j
    Ans.append(ans)

# 0-indexedなので出力時に+1
for ans in Ans:
    print(ans+1)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
int n,k,ans,m;

signed main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		int cnt=n/i;
		ans+=i*cnt*(cnt+1)/2;
	}
	cout<<ans<<endl;
}

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

typedef long long ll;
const ll MOD = 1e9 + 7;

int main() {
    string s;
    cin >> s;
    vector<vector<ll>> dp(s.length() + 1, vector<ll>(4));
    dp[0][0] = 1;
    dp[0][1] = dp[0][2] = dp[0][3] = 0;
    ll n = s.length();
    for (int i = 0; i < n; ++i) {
        dp[i + 1][0] = (s[i] == '?' ? 3ll : 1ll) * dp[i][0] % MOD;
        for (int j = 1; j <= 3; ++j) {
            dp[i + 1][j] = (s[i] == '?' ? 3ll : 1ll) * dp[i][j] % MOD;
            if (s[i] == '?' || s[i] == "ABC"[j - 1]) {
                dp[i + 1][j] += dp[i][j - 1];
                dp[i + 1][j] %= MOD;
            }
        }
    }
    cout << dp[n][3] << endl;
    return 0;
}

Measured memory_bytes: 7424
# D
K = int(input())

def snuke(n):
    return n / sum(list(map(int, list(str(n)))))

def next_snuke(k):
    strk = list(str(k))
    add = 1
    for i in range(1, len(strk)+1):
        if strk[-i] != "9":
            add = 10**(i-1)
            break
    return k+add

def is_snuke(n):
    if snuke(n) <= snuke(next_snuke(n)):
        return True
    else:
        return False
    
n = 1
while K > 0:
    print(n)
    K -= 1
    for l in range(len(str(n))+1):
        if is_snuke(n + 10**l):
            n = n + 10**l
            break



Measured memory_bytes: 3188
X = set()
for x in input():
  X.add(x)
X = sorted(X)
c = bytes(["a".encode("sjis")[0] + sum([1 for i, x in enumerate(X) if x.encode("sjis")[0] == "a".encode("sjis")[0] + i])]).decode("sjis")

if c.encode("sjis")[0] > "z".encode("sjis")[0]:
  c = "None"

print(c)


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

int main(){
  int N,A,B;
  string answer;
  cin >>N;
  if(N==1){
    answer = "Hello World ";
    cout << answer;
  }
  else{
    cin>>A>>B;
    cout << A+B;
  }
  return 0;
}
    

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

/*
AC
*/

ll modpow(__int128_t a, ll n,ll mo) {
	__int128_t r=1;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}

ll n,d[100010],a[100010]={},ans=1,mod=998244353;

int main(void){
	cin>>n;
	rep(i,n)cin>>d[i];
	rep(i,n)a[d[i]]++;
	if(a[0]!=1 || d[0]!=0)ans=0;
	reg(i,1,n-1){
		if(a[i]==0)continue;
		ans = (ans*modpow(a[i-1],a[i],mod))%mod;
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;


long long noNum , a , b , c  ;
long long v [ 100100 ] ;

int solve ( int noMoves ){
    int temp = noMoves ;


    for ( int i = 0 ; i < noNum ; i++ ){

        long long x = v [ i ] - b * noMoves ;

        if ( x < 0 ){
            continue ;
        }

        long long crMoves = x / c + 1 ;

        if ( x % c == 0 ){
            crMoves -- ;
        }

        temp -= crMoves ;

        if ( temp < 0 ){
            return 0 ;
        }

    }
    return 1 ;


}

int main(){

    scanf("%I64d%I64d%I64d",&noNum , &a , &b );

    c = a - b ;

    for ( int i = 0 ; i < noNum ; i++ ){
        scanf("%I64d",&v [ i ]);
    }

    int leftIndex = 1 , rightIndex = 1e9 ;

    while ( leftIndex < rightIndex ){
        int midIndex = ( leftIndex + rightIndex ) / 2 ;

        int val = solve ( midIndex) ;

        if ( val == 0 ){
            leftIndex = midIndex + 1;
        }else{
            rightIndex = midIndex ;
        }

    }

    printf("%d",leftIndex);

    return 0;
}


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

int main(){
  ll N;
  cin >> N;
  vector<pair<int, int>> A(N);
  for(int i=0; i<N; i++) cin >> A[i].first, A[i].second = i+1;
  
  sort(A.begin(), A.end());
  
  for(int i=0; i<N; i++){
    cout << A[i].second << " ";
  }
  
  cout << endl;
  
  
  return 0;
}

Measured memory_bytes: 3976
@$_=$_ for@p=0..<>;map{unshift@a,$#p*~-$#p/2-$%;$B=$p[$'*/ /];$A=$p[$`];@$A>@$B&&($A^=$B^=$A^=$B);$%+=@$B*map$p[$$B[@$B]=$_]=$B,@$A if$B-$A}reverse<>;print"@a"

Measured memory_bytes: 139904