akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>

void mergeSort();
void merge();

int count=0;
 
int main() 
{
  int i,n;
  int S[500000];
  
  scanf("%d",&n);
  
  for(i=0; i<n; i++) 
    scanf("%d",&S[i]);
  
  mergeSort(S,0,n);
  
  for(i=0; i<n; i++) {
    if(i>0) printf(" ");
    printf("%d",S[i]);
  }
  
  printf("\n");
  printf("%d\n",count);
 
  return 0;
}
 
void merge(int A[],int left,int mid,int right) 
{
  int i,j=0;
  int k;
  int n1 = mid-left, n2 = right - mid; 
  int L[n1+1],R[n2+1];
   
  for(i=0; i<n1; i++) 
    L[i] = A[left+i];
  for(i=0; i<n2; i++) 
    R[i] = A[mid+i];
  L[n1] = (1e+9)+1;
  R[n2] = (1e+9)+1;
  i=0;
  for(k=left; k<right; k++) {
    if( L[i] <= R[j])
      A[k] = L[i++];
    else
      A[k] = R[j++];
    count++;
  }
}
 
void mergeSort(int S[],int left,int right) 
{
  int mid;
  
  if(left+1 < right) {
    
    mid = (left+right)/2;
    
    mergeSort(S,left,mid);
    mergeSort(S,mid,right);
    merge(S,left,mid,right);
  }
  
}

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

int main()
{
    ll n, m, x;
    cin >> n >> m;
    ll sum = 0;
    while(m--){
        cin >> x;
        sum += x;
    }
    ll ans = n - sum;
    if(ans < 0)
        cout << "-1\n";
    else
        cout << ans << "\n";
}


Measured memory_bytes: 3640
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define ln '\n'
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
typedef long long ll;
typedef unsigned long long ull; 
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll K,N; cin >> K >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];

    ll p = 0;
    rep(i,N-1) chmax(p,A[i+1]-A[i]);
    chmax(p,A[0]+K-A[N-1]);

    cout << K - p << ln;
}


Measured memory_bytes: 1792
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include<stdlib.h>
#include<stdio.h>
#define test ll t; cin>>t; while(t--)
#define FOR(p,n) for(ll i=p;i<(ll)n;i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}
/*int inv[1000001]={0};
void findinverse(){inv[1] = 1;for(int i = 2; i <=1e6 ; ++i)	inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;}
*/
using namespace std;
int solve()
{
	int h, n;
	cin>>h>>n;
	int a[n],b[n];
	int mx=INT_MIN;
	for(int i=0;i<n;i++)
		cin>>a[i]>>b[i], mx=max(a[i],mx);
	int sum=h+mx;
	vector<int> dp(sum+1,1e9);
	dp[0]=0;
	for(int i=1;i<=sum;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(i-a[j]>=0)
				dp[i]=min(dp[i],dp[i-a[j]]+b[j]);
		}
	}
	int mn=INT_MAX;
	for(int i=h;i<=sum;i++)
		mn=min(mn,dp[i]);
	cout<<mn<<endl;

}
signed main()
{
	fastio;
	clock_t start, end;
//	test
	{
		start=clock();
		solve();
		end=clock();
		double time_taken=double(end-start)/double(CLOCKS_PER_SEC);
//		cout<<time_taken<<endl;
	}
}



Measured memory_bytes: 384
// Bismillahir Rahmanir Rahim .Ya Allah...
#include<bits/stdc++.h>
using namespace std;
typedef long long int  ll;
typedef pair<int,int> PII;
const int mod = 1e9+7,INF = 1e9;
const int mx = 1e5+5;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,i,j,coun =0;
    cin>>n;
    string s;
    cin>>s;
    for(int i=0,j=n-1;i<j;i++)
    {
        if(s[i]=='W')
           {
               while(s[j]!='R'&&i<j) j--;
               if(s[j]=='R')
                {
                    swap(s[i],s[j]);
                coun++;
                }
           }
    }
    cout<<coun<<endl;
    return 0;
}



Measured memory_bytes: 3744
// abc134_d.cpp
#include <iostream>
#include <vector>

using namespace std;

int main(){
	int N, A[200001], M, B[200001];
	vector<int> v;
	M = 0;
	cin >> N;
	for(int i =1; i <= N; i++){
		cin >> A[i];
	}

	for(int i = N; i>0; i--){
		int count = 0;
		int j = i;
		while (j <= N){
			count += B[j];
			j += i;
		}
		if ( count % 2 != A[i]){
			B[i] = 1;
			v.push_back(i);
			M++;
		}

	}

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

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

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

typedef long long ll;

int n;
ll p, a[10005];
string s;
int main(){
	
	cin >> n >> p >> s;
	ll rs = 0;
	if(p == 2){
		for(int i =0;i<n;i++){
			if((s[i] - '0')%2 == 0)
				rs += i+1;
		}
	}
	else
		if(p == 5){
			for(int i =0;i<n;i++){
				if((s[i] - '0')%5 == 0)
					rs += i+1;
			}
		}
		else{
			a[0] = 1;
			int cur = 0;
			ll pw10 = 1;
			for(int i = n - 1; i >= 0;i--){
				cur = (cur + pw10*(s[i] - '0')%p)%p;
				rs += a[cur];
				a[cur]++;
				pw10 = ((pw10%p)*(10%p))%p;
			}
		}
	cout << rs;

}

Measured memory_bytes: 644
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <bitset>

#include <iostream>
#include <algorithm>
#include <cmath>
#include <iterator>
#include <iomanip>
#include <random>
#include <numeric>

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

using namespace std;
// using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<double,double> pd;
typedef priority_queue<int, vector<int>, greater<int> > min_heap;

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

#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()

const double PI = 4*atan(1);
const ll INF = 1e18;
const int MX = 100001;

int n, m;
ll k;
const int maxn = 2e5 + 5;
ll a[maxn], b[maxn];
ll pa[maxn], pb[maxn];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m >> k;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        pa[i] = pa[i - 1] + a[i];
    }
    for (int i = 1; i <= m; i++) {
        cin >> b[i];
        pb[i] = pb[i - 1] + b[i];
    }
    int l = 0; int r = m;
    while (pa[l] + pb[r] > k) r--;
    int ans = l + r;
    l++;
    while (l <= n and pa[l] <= k) {
        while (pa[l] + pb[r] > k) r--;
        ans = max(ans, l + r);
        l++;
    }
    cout << ans << "\n";

}
/*
    Potential bugs:
    - Not resetting the arrays properly
    - Out of bounds
*/

Measured memory_bytes: 9836
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
inf = 10**17
mod = 10**9 + 7

a,b=MI()
print(a*b-a-b+1)

Measured memory_bytes: 3316
#include <iostream>
#include <chrono>
#include <vector>
#include <string>
#include <algorithm>
#include <map>

using namespace std;

int main() {
	vector<int> x;
	vector<int> y;
	int n;
	int tmp;
	cin >> n;
	x.resize(100001, 0);
	y.reserve(n + 1);
	for (int i = 0; i < n; i++) {
		cin >> tmp;
		x[tmp]++;
	}
	for (int i = 0; i < 100001; i++) {
		if (x[i] != 0) y.push_back(x[i]);
	}
	//for (auto yy : y) cout << yy << endl;
	int cnt = 0;
	int len = y.size();
	for (int i = 0; i < len; i++) {
		if (y[i] >= 3) {
			if (y[i] % 2 == 0)
				y[i] = 2;
			else
				y[i] = 1;
		}
	}
	int dub = count(y.begin(), y.end(), 2);
	int sing = count(y.begin(), y.end(), 1);
	//cout << dub << endl << sing << endl;
	//cout << "---" << endl;
	int t = dub / 2;
	dub -= 2 * t;
	sing += 2 * t;
	cout << sing << endl;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

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


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



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,q;
    cin>>n>>q;

    vector<tuple<int, int, int>> stx(n);
    REP(i,n) cin>>get<1>(stx[i])>>get<2>(stx[i])>>get<0>(stx[i]);

    sort(stx.begin(),stx.end());

    set<P> d;
    REP(i,q){
        int x;cin>>x;
        d.emplace(x,i);
    }

    vector<ll> tm(q,-1);
    REP(i,n){
        auto first = d.lower_bound(P(get<1>(stx[i]) - get<0>(stx[i]),0));
        auto end = d.upper_bound(P(get<2>(stx[i]) - get<0>(stx[i]) - 1, q));
        for(auto it = first;it != end;++it) tm[it->second] = get<0>(stx[i]);

        d.erase(first, end);
    }

    REP(i,q) cout<<tm[i]<<endl;
}


Measured memory_bytes: 15232
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int a, b;
    cin >> a >> b;
    if (a >= b) {
    cout << max(a, b) + max(a - 1, b) << endl;
    }
    else {
    cout << max(a, b) + max(a, b - 1) << endl;
    }
    return 0;
}

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

using namespace std;
const int mod = 1e9 + 7;

void add(int& a, int b) {
  a += b;
  if(a >= mod) {
    a -= mod;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int row, col;
  cin >> row >> col;
  vector<vector<int>> grid(row, vector<int> (col));
  for(int i = 0; i < row; i++) {
    for(int j = 0; j < col; j++) {
      char x; cin >> x;
      if(x == '.') grid[i][j] = 1;
      else grid[i][j] = 0;
    }
  }
  vector<vector<int>> dp(row, vector<int> (col, 0));
  dp[row - 1][col - 1] = (grid[row - 1][col - 1] == 1);
  for(int i = row - 1; i >= 0; --i) {
    for(int j = col - 1; j >= 0; --j) {
      if(i==row - 1 && j==col - 1) continue;
      if(grid[i][j] == 0) {
        dp[i][j] = 0;
      } else {
        if(i + 1 < row) add(dp[i][j], dp[i + 1][j]);
        if(j + 1 < col) add(dp[i][j], dp[i][j + 1]);
      }
    }
  }
  cout << dp[0][0] << '\n';
  return 0;
}


Measured memory_bytes: 11068
A = int(input())
B = int(input())
C = int(input())
X = int(input())

cnt = 0

for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if i*500 + j*100 + k*50  == X:
                cnt += 1

print(cnt)


Measured memory_bytes: 3060
#include<cstdio> 
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
#include<map>
using namespace std;
#define fo(i,j,k) for(i=j;i<=k;i++)
#define fd(i,j,k) for(i=j;i>=k;i--)
#define cmax(a,b) (a=(a>b)?a:b)
#define cmin(a,b) (a=(a<b)?a:b)
typedef long long ll;
const int N=1e6+5,M=2e6+5,mo=1e9+7;
map<int,int> Ref;
int n,i,x,a[N],b[N],c[N],d[N],pp,ans,y,fa[N],tt,act[N];
int get(int x)
{
	if (fa[x]==x) return x;
	return fa[x]=get(fa[x]);
}
int main()
{
	scanf("%d",&n);
	fo(i,1,n)
	{
		scanf("%d",a+i);
		x^=a[i];
	}
	a[n+1]=x;x=0;
	fo(i,1,n) 
	{
		scanf("%d",b+i);
		x^=b[i];
	}
	b[++n]=x;
	fo(i,1,n) c[i]=a[i],d[i]=b[i];
	sort(c+1,c+1+n);
	sort(d+1,d+1+n);
	pp=1;
	fo(i,1,n) if (c[i]!=d[i]) break;
	if (i<=n)
		printf("-1\n");
	else
	{
		 fo(i,1,n)
	        if (a[i]!=b[i]||i==n)
			{
	            if (i<n) ans++;
	            if (!Ref[a[i]]) Ref[a[i]]=++tt;
	            if (!Ref[b[i]]) Ref[b[i]]=++tt;
	        }
	    if (!ans)
		{
	        printf("0\n");
	        return 0;
	    }
	    fo(i,1,tt) fa[i]=i;
	    fo(i,1,n)
	        if (a[i]!=b[i]) fa[get(Ref[a[i]])]=get(Ref[b[i]]);
	    fo(i,1,tt)
	        if (fa[i]==i) ans++;
	    printf("%d\n",ans-1);
	}
}

Measured memory_bytes: 20864
#include<iostream>
#include<cmath>

using namespace std;

int main()
{
    double v, t, y;
    int n;

    while(cin>>v)
    {
        y=(4.9*(v/9.8)*(v/9.8))+5;

        cout<<ceil(y/5.0)<<endl;
    }


    return 0;
}

Measured memory_bytes: 1280
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

st = str(input()).split(' ')
x = int(st[0])
y = int(st[1])
ans = abs(x) + abs(y) + 10000
if x < y:
    ans = min(ans, y - x)
if -x <= y:
    ans = min(ans, 1 + y + x)
if -x < -y:
    ans = min(ans, 1 + x - y + 1)
if -y >= x:
    ans = min(ans, -y - x + 1)
print(ans)


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

int main() {
    int N, K;
    scanf("%d %d", &N, &K);
    int ans = 1;
    if (N - K > 0) ans += (N - K - 1) / (K - 1) + 1;
    printf("%d\n", ans);
    return 0;
}

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

int main()
{
  int A, B, palindromeCount;
  cin >> A >> B;
  palindromeCount = 0;
  
  for(int num = A; num <= B; num++)
  {
    int place[5];
    int rest = num;
    for(int i = 0; i < 5; i++)
    {
      place[i] = rest / pow(10, 4 - i);
      rest -= place[i] * pow(10, 4 - i);
    }
    
    if(place[0] == place[4] && place[1] == place[3])
    {
      palindromeCount++;
    }
  }
  
  cout << palindromeCount << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char a = sc.next().charAt(0);
		char b = sc.next().charAt(0);
		if (a == 'H') {
			if (b == 'H') {
				System.out.println("H");
			} else {
				System.out.println("D");
			}
		} else {
			if (b == 'H') {
				System.out.println("D");
			} else {
				System.out.println("H");
			}
		}
	}
}


Measured memory_bytes: 21844
import math

A, B = map(int, input().split())

ans = -1
for i in range(1, 1265):
  A_calc = math.floor(i*0.08)
  B_calc = math.floor(i*0.10)
  if A_calc == A and B_calc == B:
    ans = i
    break
print(ans)

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

using namespace std;
int main(void){
    int N;cin>>N;
    string s;cin>>s;
  int sum=0,B;
  for(int i=0;i<N;i++)
  {
    if(s[i]=='R')
    {
      sum++;
    }
  }
  B=N-sum;
  if(sum>B)
  {
    cout<<"Yes"<<endl;
  }
  else
  {
    cout<<"No"<<endl;
  }
}
    


Measured memory_bytes: 256
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

long long power(long long n, long long p) {
    if (p == 0)
        return 1;
    long long res = 1;
    long long add = n;
    while (p > 0) {
        if (p & 1)
            res = (res * add);
        p >>= 1;
        add = add*add;
    }
    return res;
}


int main() {
    long long n, p;
    cin >> n >> p;
    if (n == 1) {
        cout << p << endl;
        return 0;
    }
    
    long long ans = 1;
    for (long long i = 2; i*i <= p; i++) {
        int cnt = 0;
        while(p % i == 0){
            cnt++;
            p /= i;
        }

        ans *= power(i, cnt / n);

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

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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

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

  int a, b;
  string s;
  cin >> a >> b >> s;

  bool c1 = true, c2 = true;
  for (int i = 0; i <= a+b; ++i) {
    if (i == a) {
      if (s[i] != '-') c1 = false;
    }
    else {
      if (s[i] < '0' || s[i] > '9') c2 = false;
    }
  }

  cout << (c1 && c2 ? "Yes" : "No") << "\n";

  return 0;
}

Measured memory_bytes: 256
unittest
{
	assert( [ "3 2" ].parse.expand.solve == "YES" );
	assert( [ "5 5" ].parse.expand.solve == "NO" );
	assert( [ "31 10" ].parse.expand.solve == "YES" );
	assert( [ "10 90" ].parse.expand.solve == "NO" );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nk = input.front.split.to!( long[] );
	return tuple( nk[ 0 ], nk[ 1 ] );
}

auto solve( long n, long k )
{
	return ( k <= ( 1 + n ) / 2 ) ? "YES" : "NO";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x,a,b;
  cin >> x >> a >> b;
  if(b-a<=0){
    cout << "delicious" << endl;
  }else if(b-a>x){
    cout << "dangerous" << endl;
  }else{
  cout << "safe" << endl;
  }
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include <iostream>
using namespace std;
int main(){
    long i,n,t=0,a,b,min=1000000000;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a>>b;
        t=t+a+b;
        if((b<min)and(a>b)){
            min=b;
        }
    }
    t=t-2*min;
    if(min==1000000000){
        cout<<0;
        return 0;
    }
    cout<<t/2;
}

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

int main(){
    string s,t;
    cin >> s >> t;
    int len_s = s.size();
    int len_t = t.size();
    vector<char> vecs(0);
    vector<char> vect(0);
    rep(i,len_s){
        vecs.push_back(s[i]);
    }
    rep(i,len_t){
        vect.push_back(t[i]);
    }
    sort(all(vecs));
    sort(all(vect));
    reverse(all(vect));
    int count = 1;
    rep(i,min(len_s, len_t)){
        if (vecs[i] > vect[i]){
            count--;
            break;
        }
        if (vecs[i] < vect[i]){
            count++;
            break;
        }
    }
    if (count == 2 || (count == 1 && len_s < len_t)){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
ifstream f("D.in");
typedef long long ll;

int main()
{
    ll N,ans=0;
    cin>>N;
    if(N==1)
    {
        cout<<0;
        return 0;
    }
    for(ll i=2;i*i<=N;i++)
    if(N%i==0)
    {
        ll cnt=0;
        while(N%i==0) N/=i,cnt++;
        ll rez=( sqrt(1+8*cnt) -1 )/2;
        ans+=rez;
    }
    if(N!=1) ans++;
    cout<<ans;

    return 0;
}


Measured memory_bytes: 3688
#include<stdio.h>
   
int main()
{
    int a, b, c;
   
    scanf("%d %d %d\n", &a, &b, &c);
   
    if(a < b && b < c)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 584
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

int main() {
	int h, w = -1;
	cin >> h >> w;
	while (h != 0 && w != 0) {
		for (int i = h; i > 0; --i) {
			for (int j = w; j > 0; j--) {
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
		cin >> h >> w;
	}
}


Measured memory_bytes: 3072
#include<stdio.h>

typedef struct test
{
  int h;
  int w;
}test;

int main()
{
  test a[100];
  int count = 0;
  scanf("%d%d", &a[count].h, &a[count].w);
  while(a[count].h !=0 || a[count].w !=0)
    {
      count++;
      scanf("%d%d", &a[count].h, &a[count].w);
    }
  for(int i = 0; i < count; i++)
    {
      for(int j = 1; j <= a[i].h; j++)
	{
	  for(int k = 1; k <= a[i].w; k++)
	    {
	      if(j%2 == 1)
		{
		   if(k%2 == 1)
		     {
		       printf("#");
		     }
		   if(k%2 == 0)
		     {
		       printf(".");
		     }
		}
	      else
		{
		  if(k%2 == 1)
		    {
		      printf(".");
		    }
		  if(k%2 == 0)
		    {
		      printf("#");
		    }
		}
	    }
	  printf("\n");
	}
      printf("\n");
    }
}



Measured memory_bytes: 2140
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
#include <utility>
#include <cstring>
#include <numeric>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define repll(i,n) for(long long int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.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;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
template <typename T_char>
char ToUpper (char cX) { return toupper(cX); }
//g++ -std=c++1z temp.cpp
//./a.exe
ll digit(ll a){
    ll count = 0;
    for (ll i = 0; i < a; i++)
    {   if (a == 0)
        {
            break;
        }else
        {
            a = a/10;
            count++;
        }
    }
    return count;
}

uintmax_t comb(unsigned int n, unsigned int r) {
  if ( r * 2 > n ) r = n - r;
  uintmax_t dividend = 1;
  uintmax_t divisor  = 1;
  for ( unsigned int i = 1; i <= r; ++i ) {
    dividend *= (n-i+1);
    divisor  *= i;
  }
  return dividend / divisor;
}
//桁数のカウント
//pow(x,n) == x^n
//sum = accumulate(v.begin(),v.end(),0);
using Graph = vector<vector<int>>;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a,   b) * b;}


int digsum(int n) {
      int res = 0;
      while(n > 0) {
          res += n%10;
          n /= 10;
      }
      return res;
  }



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

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



//////////////////////////////////////////////////////
return 0;}


Measured memory_bytes: 3608
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    String str = sc.next();
    char[] data = str.toCharArray();


    if (data[0]==data[1]||data[1]==data[2]||data[2]==data[3]) {
      System.out.println("Bad");
    } else {
      System.out.println("Good");
    }


  }
}


Measured memory_bytes: 21844
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void){
  string pat[4] = {"dreamer", "dream", "eraser", "erase"};
  string s;
  cin >> s;
  int n = s.length();
  VI dp(n + 1);
  dp[0] = 1;
  REP(i, 0, n + 1) {
    bool found = 0;
    REP(j, 0, 4) {
      int pl = pat[j].length();
      if (i >= pl && s.substr(i - pl, pl) == pat[j]) {
	dp[i] |= dp[i - pl];
      }
    }
  }
  cout << (dp[n] ? "YES" : "NO") << endl;
}


Measured memory_bytes: 1024
M, D = map(int, input().split())

if D < 22:
  print(0)
  exit()

count = 0

for i in range(22, D+1):
  first_1 = i % 10
  second_1 = i // 10
  if first_1 < 2:
    continue
  if first_1 * second_1 <= M:
    count += 1
print(count)

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

using namespace std;

#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vii vector<pii>
#define pb push_back
#define B begin()
#define E end()
#define F first
#define S second
#define loop(z, v) for(auto &z: v)
#define nl "\n"
#define fat 1000000007

int main()
{
    boost
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;

    vi p(a), q(b), r(c);
    loop(z, p) cin >> z;
    loop(z, q) cin >> z;
    loop(z, r) cin >> z;

    sort(p.B, p.E, greater<int>());
    sort(q.B, q.E, greater<int>());
    sort(r.B, r.E, greater<int>());

    vi tot;
    for(int i = 0; i < x; i++) tot.pb(p[i]);
    for(int i = 0; i < y; i++) tot.pb(q[i]);

    sort(tot.B, tot.E);

    for(int i = 0; i < c && i < tot.size(); i++)
    {
        if(tot[i] < r[i]) tot[i] = r[i];
    }

    cout << accumulate(tot.B, tot.E, 0LL) << nl;
    return 0;
}

Measured memory_bytes: 2552
#include <stdio.h>
#include <stdlib.h>

void merge_sort(int x[], int n)
{
	static int y[100001] = {};
	if (n == 1) return;
	merge_sort(&(x[0]), n/2);
	merge_sort(&(x[n/2]), (n+1)/2);
	
	int i, p, q;
	for (i = 0, p = 0, q = n/2; i < n; i++) {
		if (p >= n/2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p] < x[q])? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

int main()
{
	int i, N, C, K, T[100001] = {};
	scanf("%d %d %d", &N, &C, &K);
	for (i = 0; i < N; i++) scanf("%d", &(T[i]));

	int bus = 0, count, early;
	merge_sort(T, N);
	T[N] = T[N-1] + K + 1;
	for (i = 1, count = 1, early = T[0]; i <= N; i++) {
		if (count >= C || T[i] > early + K) {
			count = 1;
			early = T[i];
			bus++;
		} else count++;
	}
	
	printf("%d\n", bus);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std;
int check(string str) 
{ 
   
    int n = str.length(); 
    int digitSum = 0; 
    for (int i=0; i<n; i++) 
        digitSum += (str[i]-'0'); 
  
  
    return (digitSum % 9 == 0); 
} 
int main(){
    string n;
    cin>>n;
  check(n)?  cout << "Yes" : cout << "No "; 

}

Measured memory_bytes: 3864
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
  
int p[222];
void init(int n){ for(int i = 0; i <= n; i++) p[i] = i; }
int find(int x){ return p[x] = ( (p[x] == x)?x:find(p[x])); }
void merge(int x,int y){ p[find(x)] = find(y); }
bool same(int x,int y){ return find(x) == find(y); }
  
bool used[222];
  
int n,m;
int h[222];
vector<int> s[1111111];
int a[44444],b[44444],c[44444];
pair<int,pair<int,int> > e[44444];
int main(void){
  
  while(cin >> n >> m && n){
    int ans = 0;
    init(n);
    memset(used,false,sizeof(used));
  
    for(int i = 0; i < 1111111; i++) s[i].clear();
  
    for(int i = 0; i < n; i++){
      cin >> h[i];
      s[ h[i] ].push_back(i+1);
    }
  
    for(int i = 0; i < m; i++){
      cin >> a[i] >> b[i] >> c[i];
      e[i] = make_pair(c[i],make_pair(a[i],b[i]));
    }
    sort(e,e+m);
      
    int c = 0;
    int f = -1;
    for(int t = 1000000; t > 0; t--){

      bool flag = false;
      for(int i = 0; i < (int)s[t].size(); i++){
    used[ s[t][i] ] = true;
    f++;
    c++;
flag = true;
      }
      if(flag && f > 0){
    for(int i = 0; i < m; i++){
      int u = e[i].second.first, v = e[i].second.second;
      //cout << u << " " << v << endl;
      if(used[u] && used[v] && !same(u,v) ){
        merge(u,v);
        ans += e[i].first;
        f--;
      }
    }
    if(f > 0){
      ans = 0;
      init(n);
      f = c-1;
    }
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 28092
import java.util.*;
import java.io.*;

public class Main {

    static int MOD = (int) 1e9+7;

    static int n, x, y, z;
    static int[][] dp;

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        PrintWriter pw = new PrintWriter(System.out);

        n = fs.nextInt(); x = fs.nextInt(); y = fs.nextInt(); z = fs.nextInt();

        dp = new int[n+1][1 << (x + y + z + 1)];
        dp[0][1] = 1;

        int p = 0;
        for (int i = 0; i < n; i++) {
            for (int j =0; j < 1 << (x + y + z + 1); j++) {
                if (dp[i][j] > 0) {
                    for (int A = 1; A <= 10; A++) {
                        p = 0;
                        //start
                        if ((j & 1) == 1) {
                            p |= (1 << 0);
                        }
                        for (int k = 0; k < x; k++) {
                            if ((((j >> k) & 1) == 1) && k + A <= x) {
                                p |= 1 << (k + A);
                            }
                        }
                        for (int k = x; k < x + y; k++) {
                            if ((((j >> k) & 1) == 1) && k + A <= x + y) {
                                p |= 1 << (k + A);
                            }
                        }
                        for (int k = x + y; k < x + y + z; k++) {
                            if ((((j >> k) & 1) == 1) && k + A <= x + y + z) {
                                p |= 1 << (k + A);
                            }
                        }
                        if (((j >> x + y + z) & 1) == 1) {
                            p |= 1 << (x + y + z);
                        }
                        dp[i + 1][p] = (dp[i + 1][p] + dp[i][j]) % MOD;
                    }
                }
            }
        }
        int ans = 0;
        for (int i = 0; i < 1 << (x + y + z + 1); i++) {
            if ((((i >> x + y + z) & 1) == 1) && dp[n][i] > 0) {
                ans = (ans + dp[n][i]) % MOD;
            }
        }
        pw.println(ans);
        pw.flush();
    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }

        public FastScanner() {
            this(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
    }
}

Measured memory_bytes: 82584
#include <iostream>
using namespace std;
#define FOR(i,a,n) for(int i = a; i < n ;i++)
#define REP(i,n) FOR(i,0,n)

int main(){
  int n;
  while(cin >> n){
    int cnt = 0;
    REP(a, 1001){
      if(a > n) break; 
      REP(b, 1001){
	int ab = a + b;
	if(ab > n) break;
	if(n - ab <= 2000){
	  cnt +=  min(n - ab, 2000 - n + ab) + 1;
	}
      }
    }
    cout << cnt << endl;
  }

  return 0;
}


Measured memory_bytes: 1164
#include <vector>
#include <string>
#include <iostream>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <functional>
#include <map>
#include <array>
#include <cmath>
#include <set>
#include <numeric>

using namespace std;

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

using LONG = long long;
using LVEC = vector<long long>;

#define FOR(_i, s, e) for(_i = s; _i < e; ++_i)
#define FOR_INV(_i, s, e) for(_i = e - 1; _i >= s; --_i)

long long PRIME = 1e9 + 7;
long long PRIME2 = 998244353;


using pos = std::pair<LONG, LONG>;



//int main(){
//    LONG i, j, k;
//    LONG A;
//    double B;

//    cin >> A >> B;

//    LONG r = A * (B * 100);
//    cout << r / 100;
//}



map<LONG, LONG> p_counts;


void primes(LONG N){
    if(N <= 1)return;

    LONG i;
    LONG l = sqrt(N) + 1;
    FOR(i, 2, l){
        if(N % i == 0){
            primes(i);
            primes(N / i);
            return;
        }
    }

    p_counts[N]++;
    return;
}


LONG num(LONG count){
    LONG sum = 0;
    LONG cur = 0;

    while(sum <= count){
        sum += ++cur;
    }

    return cur - 1;
}


int main(){
    LONG N;
    cin >> N;

    primes(N);

    LONG ret = 0;
    for(auto i = p_counts.begin(); i != p_counts.end(); ++i){
        ret += num(i->second);
    }

    cout << ret;
}


Measured memory_bytes: 3652
#include <iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

int main(void)
{
	int H, W;
	cin >> H >> W;

	int N;
	cin >> N;

	int x, y;
	x = y = 0;
	vector<vector<int>> table(H, vector<int>(W, 0));
	for(int i=1; i<=N; i++)
	{
		int a;
		cin >> a;

		for(int j=0; j<a; j++)
		{
			table[y][x] = i;

			if(y%2 == 0)
			{
				x++;
				if(x == W)
				{
					y++;
					x = W-1;
				}
			}
			else
			{
				x--;
				if(x == -1)
				{
					y++;
					x = 0;
				}
			}
		}
	}

	for(int i=0; i<H; i++)
	{
		cout << table[i][0];
		for(int j=1; j<W; j++)
			cout << " " << table[i][j];
		cout << endl;
	}

	return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n),b(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
    b.at(i) = a.at(i);
  }
  sort(b.begin(), b.end());
  int x = 0;
  for(int i=0;i<n;i++){
    if(a.at(i)  !=  b.at(i)){
      x++;
    }
  }
  if(x == 0 || x == 2){
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		for (;;) {
			int n = s.nextInt(), a = s.nextInt(), b = s.nextInt(), c = s
					.nextInt(), x = s.nextInt();
			if (n < 1) {
				break;
			}

			int rs[] = new int[n];
			for (int i = 0; i < n; ++i) {
				rs[i] = s.nextInt();
			}

			int count = 0, i = 0;
			for (;count <= 10000; ++count) {
				int r = rs[i];
				if (r == x) {
					++i;
				}
				x = (a * x + b) % c;
				if (i == n) {
					break;
				}
			}
			System.out.println(count > 10000 ? -1 : count);
		}
	}
}

Measured memory_bytes: 31692
#include<iostream>
#include<vector>

using namespace std;
bool binary_Search(vector<int> S,int n, int key ){
  int left=0;
  int  right= n;
  int mid=0;
  while(left < right){
    mid = (left + right)/2;
    if(S[mid]== key){
      return true;
    }
    else if (key< S[mid]){
      right = mid;
    }
    else {
      left = mid +1;
    }
  }
  return false;
}

int main(){
 size_t n,q;
 int count=0,key=0;
 cin >> n;
 vector<int> S(n);
  for(size_t i=0;i< n ; i++ ){
    cin>> S[i];
  }
  cin>> q;
  vector<int> T(q);
 for(size_t j=0;j< q ; j++) {
     cin >> T[j];
     key = T[j];
  if(binary_Search(S,n,key)==true){
  count++;
  }
 }

  cout<< count<< endl;


 return 0;

}



Measured memory_bytes: 3772
// C.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

int main(int argc, char* argv[]) {
	while (true) {
		int n = -1, k, q;
		cin >> n >> k >> q;
		if (n <= 0) break;
		vector<int> v(n);
		for (int i = 0; i < q; ++i) {
			int a;
			cin >> a;
			v[a - 1] += 1;
		}
		for (int i = 0; i < n; ++i) {
			cout << ((k + v[i] - q) > 0 ? "Yes" : "No") << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
 
int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int cnt =0;
  char old_s = ' ';
  rep(i,n){
    char new_s = s.at(i);
    if(new_s == old_s){
      cnt++;
    }else{
      old_s = new_s;
    }
  }

  cout << n-cnt << endl;

}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
int gcd(int a,int b)
{
    if(a==0)return b;
    return gcd(b%a,a);
}
int lcm(int x,int y)
{
    return (x*1ll*y/gcd(x,y));
}
int32_t main()
{
	IOS;
    int n;
    cin>>n;
    int a[n];
    int k=1,t=0;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)
    {
        if(a[i]!=k)
        t++;
        else
        k++;
    }
    if(t==n)
    cout<<"-1"<<endl;
    else
    cout<<t<<endl;
	return 0;
}

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

int main ( void ) {

	int n, m;
	std::cin >> n >> m;

	int hash = 0;
	for ( int i = 0 ; i < m ; i++ ) {
		int val;
		std::cin >> val;
		hash |= ( 1 << val );
	}

	while ( true ) {
		int val = 0;
		for ( int x = n ; x > 0 ; x /= 10 ) {
			val |= ( 1 << ( x % 10 ) );
		}
		if ( ( val & hash ) == 0 ) {
			std::cout << n << std::endl;
			break;
		}
		++n;
	}
	return 0;
}

Measured memory_bytes: 256
#include "bits//stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define ALL(v) v.begin(), v.end()
ll dp[2001][2001][2];
ll mod_pow(ll a, ll n) {
	if (n == 0) return 1;
	if (n % 2 == 0) {
		ll tmp = mod_pow(a, n / 2);
		return (tmp * tmp) % MOD;
	}
	return (a * mod_pow(a, n - 1)) % MOD;
}
int main() {
	int N, K;
	cin >> N >> K;
	dp[N][0][0] = 1;
	for (int i = N; i >= 1; i--) {
		for (int j = N; j >= 0; j--) {
			(dp[i - 1][j][0] += dp[i][j][0] + dp[i][j][1]) %= MOD;
			(dp[i - 1][j + 1][1] += dp[i][j][0] + dp[i][j][1]) %= MOD;
			if (j > 0) (dp[i][j - 1][0] += dp[i][j][0]) %= MOD;
		}
	}
	ll ret = (dp[1][N - K][0] + dp[1][N - K][1]) % MOD;
	if (N - K - 1 >= 0) (ret *= mod_pow(2, N - K - 1)) %= MOD;
	cout << ret << endl;
}

Measured memory_bytes: 62848
//#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define _GLIBCXX_DEBUG // ArrayOutofBounds
#define rep(i, N) for (int i = 0; i < N; i++) //制御変数iを用いてN回転
using namespace std;
using ll = long long;

int main() {
    int N, count = 0;
    cin >> N;
    vector<ll> L(N);
    rep(i, N) cin >> L[i];
    sort(L.begin(), L.end());
    for (int i = 0; i < N - 2; i++) {
        for (int j = i; j < N - 1; j++) {
            if (L[i] == L[j]) continue;
            for (int k = j; k < N; k++) {
                if (L[j] == L[k]) continue;
                if (L[i] + L[j] > L[k]) count++;
            }
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3632
n=int(input())
i=list(map(int,input().split()))
i.sort()
temp=1
size=i[0]
for k in range(1,n):
  if size*2>=i[k]:
    temp+=1
    size+=i[k]
  else:
    temp=1
    size+=i[k]
print(temp)


Measured memory_bytes: 14396
N = int(input())
ans = N
for i in range(N + 1):
  c = 0
  t = i
  while t > 0:
    c += t % 6
    t //= 6
  t = N - i
  while t > 0:
    c += t % 9
    t //= 9
  ans = min(ans, c)
print(ans)

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

using namespace std;

char a[52][52];
char b[52][52];
bool check;

int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    check = false;
    for(int i = 0; i < n; i++) {
        scanf("%s", a[i]);
    }
    for(int i = 0; i < m; i++) {
        scanf("%s", b[i]);
    }
    for(int p = 0; p <= n - m; p++) {
        for(int q = 0; q <= n - m; q++) {
            check = true;
            for(int i = p; i < p + m; i++) {
                if(check == false) break;
                for(int j = q; j < q + m; j++) {
                    if(a[i][j] != b[i - p][j - q]) check = false;
                    if(check == false) break;
                    if(i == p + m - 1 && j == q + m - 1 && check == true) printf("Yes\n");
                }
            }
            if(check == true) break;
            else check = false;
        }
        if(check == true) break;
    }
    if(check == false) printf("No\n");
    return 0;
}


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

int main(){
	string s; cin>>s;
	int mini = INT_MAX;
	for(int i=0; i<=s.size()-3; ++i){
		int a = (s[i]-'0')*100 + (s[i+1]-'0')*10 + (s[i+2]-'0');
		mini = min(mini, abs(753 - a));
	}
	cout<< mini <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_set>
#include <algorithm>
#include <cmath>

using namespace std;

template <int base>
int digit_sum(int n)
{
	int sum = 0;
	while (n > 0) {
		sum += n % base;
		n /= base;
	}
	return sum;
}

using ivec = vector<int>;

ivec read_int_args()
{
	int N;
	cin >> N;
	ivec v(N);
	for (auto& e : v) {
		cin >> e;
	}
	return v;
}

int compar(const void * b, const void* a)
{
	return (*(int*)a - *(int*)b );
}

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

int main()
{
	int K, S;
	cin >> K >> S;
	
	int sum = 0;
	
	for (int X = 0; X <= K; X++)
	for (int Y = 0; Y <= K; Y++)
	{
		int Z = S - X - Y;
		if (0 <= Z && Z <= K) sum++;
		
	}

	cout << sum << endl;

	return 0;
}


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

class Program
{
    static void Main(string[] args) {
        long[] s = Console.ReadLine().Split().Select(long.Parse).ToArray();
        Console.WriteLine(solve(s[0], s[1], s[2], s[3], s[4]));
    }
    static long solve(long a, long b, long c, long x, long y) {
        long ans = 0L;
        long min = Math.Min(a+b,c*2);
        long max = (x<y ? Math.Min(b,c*2) : Math.Min(a,c*2));
        for(long i = 0L; i < Math.Min(x,y); i ++) ans += min;
        for(long i = Math.Min(x,y); i < Math.Max(x,y); i ++) ans += max;
        return ans;
    }
}

Measured memory_bytes: 13396
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"

const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,1,0,-1 };
map<pair<int, int>, pair<int, int>>mp;
struct aa {
	int x;
	int y;
	int way;
	int foot;
};
int main() {
	while (1) {
		mp.clear();
		int N; cin >> N;
		if (!N)break;
		for (int i = 0; i < N; ++i) {
			int x, y; char c; cin >> x >> y >> c;
			if (c == 'x')
			{
				mp[make_pair(x, y)] = make_pair(2, -1);
				mp[make_pair(x+1, y)] = make_pair(0, -1);
			}
			else {
				mp[make_pair(x, y)] = make_pair(1, -1);
				mp[make_pair(x, y+1)] = make_pair(3, -1);
			}

		}
		bool ok = true;
		for (auto& m : mp) {
			if (m.second.second == -1) {
				m.second.second = 0;
				queue<aa>que;
				que.push(aa{ m.first.first,m.first.second,m.second.first,0 });
		
				while (!que.empty()) {
					aa atop(que.front());
					que.pop();
					const int nowx = atop.x;
					const int nowy = atop.y;
					const int nowf = atop.foot;
					for (int way = 0; way < 4; ++way) {
						const int newx = nowx + dx[way];
						const int newy =nowy+ dy[way];
						const int newf = way == atop.way ? !nowf : nowf;
						if (mp.find(make_pair(newx, newy)) != mp.end()) {
							if (mp[make_pair(newx, newy)].second == -1) {
								mp[make_pair(newx, newy)].second = newf;
								que.push(aa{ newx,newy,mp[make_pair(newx,newy)].first,newf });
							}
							else {
								if (mp[make_pair(newx, newy)].second != newf)ok = false;
							}
						}
					}
				}
				
			}
		}
		if (ok)cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	
	return 0;
}

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

#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

namespace {
    void printElems(const int* begin, const int* end)
    {
        for (const int* p = begin; p != end; ++p) {
            std::cout << *p << std::ends;
        }
        std::cout << std::endl;
    }
}

int main() {
  // 3個の入力を受け取れるように 3要素の配列 {0, 0, 0} で初期化
  int n;
  cin >> n;
  int vec[n];
 
  for(int i = 0; i < n ; i++){
    // atを使って1つずつ入力
    cin >> vec[i] ;

  }

  std::sort(vec, vec + SIZE_OF_ARRAY(vec));

  
  double start = vec[0];
  double value = start;
  for(int i = 1; i < n ; i++){
    value =(vec[i]+value)/2;
   
  }

  cout << value << endl;  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll n;
string s;
int left(string s,int i,int cnt){
    if(i-1!=-1){
        if(s[i-1]==s[i]) {
            return left(s,i-1,cnt+1);
        }
        else return cnt;
    }
    else return cnt;
}
int right(string s,int i,int cnt){
    if(i+1!=s.size()){
        if(s[i+1]==s[i]) {
            return (s,i+1,cnt+1);
        }
        else return cnt;
    }
    else return cnt;
}
int main(){
    cin>>n;
    cin>>s;
    /*
    vector<int> v(n,0);
    for(int i = 0;i < n; i++){
        v[i]=max(left(s,i,0),right(s,i,0));
    }
    int cntcnt=0;
    for(int i = 0;i < n; i++){
        if(v[i]==1) cntcnt++;
    }
    for(int i = 0;i < n; i++){
        cout<<v[i]<<endl;
    }
    cout<<cntcnt<<endl;
    cout<<n-cntcnt<<endl;
    */
   int cnt=1;
   for(int i = 0;i < n-1; i++){
       if(s[i]!=s[i+1]) cnt++;
   }
   cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main() {
	int q, p, n; cin >> q;
	char c;
	long long cnt[2] = {};
	while (q--) {
		cin >> p >> c >> n;
		cnt[c - '('] += n;
		if (cnt[0] == cnt[1]) cout << "Yes" << endl;
		else cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 3084