akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 1000000000
#define LLINF 2000000000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
#define int long long

int modpow(int a,int n, int mod){
	int res = 1;
	while(n > 0){
		if(n&1) res = res * a % mod;
		a = a*a % mod;
		n >>= 1;
	}
	return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

signed main(){
	int x,y;
	cin >> x >> y;
	if((x+y)%3){
		cout << 0 << endl;
		return 0;
	}
	if(x*2<y || y*2<x){
		cout << 0 << endl;
		return 0;
	}

	// 答えは　nCk としておく
	int n = (x+y)/3;
	int k = x-n;
	int ans = 1;
	int mod = 1000000007;
	// cerr << n << ":" << k << endl;
	LOOP1(i,k){
		ans = ans * (n-i+1) % mod;
		// cerr << "*" << ans;
		ans = ans * modinv(i,mod) % mod;
		// cerr << "*" << ans << endl;
	}
	cout << ans << endl;
}


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

int dp[100][5][2];
vector<int> arr;

int check(int pos,int count,bool flag,int k,int sz){
    if(pos>=sz) return count==k?1:0;
    if(count > k) return 0;
    if(dp[pos][count][flag] != -1) return dp[pos][count][flag];
    
    int limit = 9;
    if(!flag) limit = arr[pos];
    
    int res = 0;
    for(int i=0;i<=limit;i++){
        if(flag || i<limit){
            if(i==0) res+= check(pos+1,count,true,k,sz);
            else res+= check(pos+1,count+1,true,k,sz);
        }
        else{
            if(i==0) res+= check(pos+1,count,false,k,sz);
            else res+= check(pos+1,count+1,false,k,sz);
        }
    }
    
    dp[pos][count][flag] = res;
    return res;
}

int main() {
	string s;
	int k;
	cin >> s;
	cin >> k;
	for(int i=0;i<100;i++)
	    for(int j=0;j<5;j++)
	        for(int k=0;k<2;k++)
	            dp[i][j][k] = -1;
	for(auto i:s){
	    arr.push_back(i-'0');
	}
	cout << check(0,0,false,k,s.size());
	return 0;
}

Measured memory_bytes: 3600
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String ans = "";
        for (int i = 0 ; i < s.length() ; i++) {
            String c = s.substring(i, i + 1);
            if (c.equals("B") && ans.length() > 0){
                ans = ans.substring(0, ans.length() - 1);
            } else if (c.equals("0")) {
                ans += "0";
            } else if (c.equals("1")) {
                ans += "1";
            }
        }
        System.out.println(ans);
    }

}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
#define pb push_back
#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define ll long long int
#define ld long double
#define el '\n'
#define PI (ld)3.14159265358979323846
#define inf (ll)1000000000
#define mod (ll)1000000007
#define mod1 (ll)998244353
#define fo(i, n) for (long long i = 0; i < int(n); i++)
#define pll pair<ll, ll>
#define ff first
#define ss second
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define sz(a) a.size()
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define vl vector<ll>
//#define x ff
//#define y ss
#define pt(a) for(auto it:a)cout<<it<<" ";cout<<endl;
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
using namespace std;

double gcd(double a, double b) { return a < 0.01 ? b : gcd(fmod(b, a), a); }

/*vector<int> parent, rak;

int find_set(int v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}

void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (rak[a] < rak[b])
            swap(a, b);
        parent[b] = a;
        rank[a]+=rank[b];
    }
}*/

long long bpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % m;
      a = a * a % m;
      b >>= 1;
  }
  return res;
}
ll extend_gcd(ll a,ll b,ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1,y1;
    ll ans =extend_gcd(b,a%b,x1,y1);
    x=y1;
    y=x1-(a/b)*y1;

    return ans;
}
ll inverse(ll a,ll m){
    ll x,y;
    extend_gcd(m,a,x,y);
    y%=m;
    y+=m;
    y%=m;
    return y;
}

/*const int N = 1000001;
int lp[N+1];
vector<int> pr;
void s(){
for (int i=2; i<=N; ++i) {
        if (lp[i] == 0) {
            lp[i] = i;
            pr.push_back (i);
        }
        for (int j=0; j<(int)pr.size() && pr[j]<=lp[i] && i*pr[j]<=N; ++j)
            lp[i * pr[j]] = pr[j];
    }
}*/


ll kv;
ll t,n,x,y,h,k,z,p,q,w;

vector<vector<pll>>v,v1,v2;
//vector<ll>vis,d;
  

int main() {
    IOS;
    cin>>n;
    vl a(n,0),b(n,0);
    fo(i,n)cin>>a[i];
    fo(i,n)cin>>b[i];
    fo(i,n)kv+=(a[i]>b[i]?a[i]-b[i]:0);
    cout<<kv;
    return 0;
}


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

using namespace std;
int N;
long int s[202];

int main(){
  cin >> N;
  int ans=1000;
  int tmp=0;
  for(int i=0;i!=N;i++){
    cin >> s[i];
    if(s[i]%2==1){
      ans=0;
      break;
    }
    while(s[i]%2==0){
      tmp++;
      s[i]=s[i]/2;
    }
    if(ans>tmp){
      ans=tmp;
    }
    tmp=0;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
using System;

namespace transfer
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int[] a = new int[3];
            for(int i=0;i<=2;i++){
                a[i] = int.Parse(s[i]);
            }
          if(a[1]+a[2]-a[0] <= 0){
            Console.WriteLine(0);
          }else{
            Console.WriteLine(a[1]+a[2]-a[0]);
          }
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define rep(i, n) for(long i = 0; i < n; i++)
#define erep(i, n) for(long i = 1; i <= n; i++)
const long MOD = 1000000007;
#define all(a) a.begin(), a.end()
#define eall(a) a.begin()+1, a.end()
#define show(ans)  cout << ans << endl;

int main(){
long N, L;
cin >> N >> L;
vector<long> t(N+1);
vector<pair<long, long>> p;
long sum, ans;
erep(i, N) {
    t[i] = L + i - 1;
    p.push_back(make_pair(abs(L + i - 1), i));
}
sort(all(p));
sum = (2*L + N - 1) * N / 2;
ans = sum - t[p[0].second];
show(ans);

return 0;
}

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

int main(){
  int n; cin>>n;
  int ans=0;
  vector<int> a(n);
  
  for(int i=0;i<n;i++){
    cin>>a[i];
    ans+=a[i]-1;
  }
  
    cout<<ans<<endl;
}

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

#define INF 2147483647

class segtree{
public:
  int Node;
  vector<int> table;
  segtree(int);
  int ope(const int,const int);
  void update(int index,const int value){ // index is 0-indexed.
    index += Node; // query function
    table[index] = value;
    while(index > 0){
      index /= 2;
      table[index] = ope(table[2*index],table[2*index+1]);
    }
  }
  int find(int l, int r);
};
int segtree::find(int l,int r){ // l,r is 0-indexed.
    if(l == r) return table[r+Node];
    l += Node; r += Node;
    int ans = INF;
    for(; l <= r;l >>=1, r >>=1){
      if(r == l){ans=ope(ans,table[l]); return ans;}
      if(r%2 == 0) ans=ope(ans,table[r]),--r;
      if(l%2) ans=ope(ans,table[l]),++l;
    }
    return ans;
}
segtree::segtree(int Max_Node){  // initialize
  Node = 2;
  while(Node < Max_Node)
    Node *= 2;
  table.resize(2*Node);
  for(int i = Node;i < Node*2; i++)
    table[i] = INF; // initialize
  for(int i= Node-1; i > 0; i--)
    table[i] = ope(table[i*2],table[i*2+1]);
}

int segtree::ope(const int a,const int b){
  return min(a,b);
}

int main () {
  int n,q;cin>>n>>q;
  segtree st(n);
  for(int i=0;i<q;++i){
    int c,x,y;cin>>c>>x>>y;
    if(c==0)
      st.update(x,y);
    else
      cout<<st.find(x,y)<<endl;
  }
}

Measured memory_bytes: 3796
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

const int N = 120000;

int n, m;
vector<int> eds[N];
int cl[N];
int was[N];
int h[N];

vector<pair<int, int>> ans;


void add(int x, int y) {
	cl[x] ^= 1;
	ans.emplace_back(x + 1, y + 1);
}

void dfs1(int v, int p) {
	was[v] = 1;
	for (int u: eds[v]) {
		if (!was[u]) {
			h[u] = h[v] + 1;
			dfs1(u, v);
		}
		else if (h[u] < h[v] - 1) {
			add(v, u);
		}
	}
	if (cl[v])
		add(v, p);
	else if (p != -1)
		add(p, v);
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cout.setf(ios::fixed), cout.precision(20);
	cin >> n >> m;
	if (m % 2 != 0) {
		cout << -1 << "\n";
		return 0;
	}
	for (int i = 0; i < m; ++i) {
		int a, b;
		cin >> a >> b;
		--a, --b;
		eds[a].push_back(b);
		eds[b].push_back(a);
	}
	dfs1(0, -1);
	for (auto p: ans)
		cout << p.first << " " << p.second << "\n";
	return 0;
}




Measured memory_bytes: 17268
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const long double PI = acos(-1);
#define chmin(i, j) i = min(i, j);
#define chmax(i, j) i = max(i, j);
#define rep(i, n) for(int i=0;i<n;i++)
ll MOD = 1000000007;
ll fact(ll m) {
  if(m == 0 || m == 1) return 1LL;
  else return (m * fact(m-1LL)) % MOD;
}
bool custom(pair<ll, ll> a, pair<ll, ll> b) {
  if(a.first == b.first) return (a.second > b.second);
  else return a.first < b.first;
}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main() {
  string L;
  cin >> L;
  vector<int> setted;
  for(int i=0;i<L.size();i++) {
    if(L[i] == '1') setted.emplace_back(i);
  }
  long long ln = L.size();
  long long n = setted.size();
  long long ans = 0;
  for(int i=0;i<n+1;i++) {
    if(i == 0) ans += modpow(2LL, n, MOD);
    else {
      ans += modpow(2LL, (long long)i-1LL, MOD) * modpow(3LL, ln - (long long)setted[i-1] - 1LL, MOD);
      ans %= MOD;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1020
#include <stdio.h>
#include <set>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <vector> 
#include <string>
#include <string.h>
#define LL long long
using namespace std;


int main()
{
    char s[100000];
    scanf("%s",s);
    for (int i=0;i<strlen(s);i=i+2)
    {
    cout<<s[i];
    }
    return 0;
    
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(),v.end()
#define pii pair< ll,ll>
#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define mp make_pair
#define ll long long int
#define mod 1000000007
#define mxn 2000002
#define sqr 320
ll pre1[1000]={0},pre2[1000]={0};
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n,i;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        ll l ;
        cin>>l;
        pre1[i]=pre1[i-1]+l;
    }
    for(i=1;i<=n;i++)
    {
        ll l;
        cin>>l;
        pre2[i]=pre2[i-1]+l;
    }
    ll ans = 0 ;
    for(i=1;i<=n;i++)
    {
        ans=max(ans,pre1[i]+pre2[n]-pre2[i-1]);
    }
    cout<<ans;
    return 0;
    }

Measured memory_bytes: 256
#include <iostream>
#include<stdio.h>
#include<stdlib.h>

int main()
{
  int n,k,d,a;
  bool sunu[100];
  int i,j;
  int result;
  
  result = 0;
  for(i = 0; i < 100; i++)
  {
    sunu[i] = false; 
  }
  
  scanf("%d",&n);
  scanf("%d",&k);

  for(i = 0; i < k; i++)
  {
    scanf("%d",&d);
    for(j = 0; j < d; j++)
    {
      scanf("%d",&a);
	  sunu[a-1] = true;      
    }
  }
  
  for(i = 0; i < n; i++)
  {
     if(sunu[i] == false)
       result++;
  }
  
  printf("%d\n",result);
  
  return 0;
}

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

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

typedef long long ll;

const int mod = 1e9 + 7;

using namespace std;



int main(void) {
	int N, M; cin >> N >> M;
	vector<pair<ll, ll>> d(N);

	rep(i, N)cin >> d[i].first >> d[i].second;

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

	ll ans = 0;
	ll cnt = 0;

	for (auto x : d) {
		ll n = min(x.second, M - cnt);
		cnt += n;
		ans += n * x.first;
		if (cnt >= M)break;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4828
#include<bits/stdc++.h>
using namespace std;
bool water[30+5];
int sugar[3000+5];
int main()
{
	int A,B,C,D,E,F;
	scanf("%d%d%d%d%d%d",&A,&B,&C,&D,&E,&F);
	
	water[0]=1;
	for(int i=0;i+A<=F/100;++i)water[i+A]|=water[i];
	for(int i=0;i+B<=F/100;++i)water[i+B]|=water[i];
	sugar[0]=1;
	for(int i=0;i+C<=F;++i)sugar[i+C]|=sugar[i];
	for(int i=0;i+D<=F;++i)sugar[i+D]|=sugar[i];
	sugar[0]=0;
	for(int i=1;i<=F;++i)sugar[i]=sugar[i]?i:sugar[i-1];
	
	double ans=0,tmp;
	int summass=100*A,sugarmass=0;
	for(int i=1;100*i<=F;++i)
		if(water[i]){
			int a=100*i,b=sugar[min(F-a,E*a/100)];
			if((tmp=(double)b/(a+b))>ans){
				ans=tmp;
				summass=a+b,sugarmass=b;
			}
		}
	printf("%d %d\n",summass,sugarmass);
}

Measured memory_bytes: 256
N,C,*D=`dd`.split.map &:to_i
a=[],[],[]
(N*N).times{|i|a[(i/N+i%N)%3]<<D.pop-1}
r=*0...C
s,t,u=a.map{|e|r.map{|t|s=0;e.map{|f|s+=D[f*C+t]};s}}
p r.permutation(3).map{|x,y,z|s[x]+t[y]+u[z]}.min

Measured memory_bytes: 45408
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
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;
            if(i*10000+5000*j+1000*k == y) {
                printf("%d %d %d\n",i,j,k);
                return 0;
            }
        }
    }
    printf("%d %d %d\n",-1,-1,-1);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct ios_accelerate { ios_accelerate() { ios::sync_with_stdio(false); cin.tie(nullptr); } } CALL;

#define REP(i, n) for(auto (i) = (n)*0; (i) < (n); (i)++)
#define RNG(i, a, b) for(auto (i) = (a); (i) < (b); (i)++)
#define RBF(i, v) for(auto& (i) : (v))
#define ALL(x) (x).begin(), (x).end()

using LL = long long;
using UL = unsigned long;
using ULL = unsigned long long;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
template<typename T> using P = pair<T, T>;

const double PI = 3.141592653589793;
const int MOD = 1000000007;
const LL INF64 = static_cast<LL>(1e18) + 2;
const int INF = static_cast<int>(1e9) + 2;

template<typename T> inline void upsort(vector<T>& x) { sort(x.begin(), x.end()); }
template<typename T> inline void downsort(vector<T>& x) { sort(x.begin(), x.end(), greater<T>()); }
template<typename T> inline void col(T x) { cout << x << '\n'; }
template<> inline void col(double x) { cout << fixed << setprecision(12) << x << '\n'; }

signed main() {
	int n, k;
	cin >> n >> k;

	int keta = 0;
	while (n>0) {
		n /= k;
		keta++;
	}
	col(keta);
	return 0;
}


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

using namespace std;



int main(){
 priority_queue <ll> que;
 ll n,m,a,ans=0;
 cin>>n>>m;
 rep(i,n){
     cin>>a;
     que.push(a);
 }
 rep(i,m){
     ll temp=que.top()/2;
     que.pop();
     que.push(temp);
 }
 rep(i,n){
     ans+=que.top();
     que.pop();
 }
 cout<<ans<<endl;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;
LL D[100001];
LL c[100001];
LL MOD=998244353;
int main(){
	cin>>N;
	REP(i,N){
		cin>>D[i];
	}
	if(D[0]!=0){
		cout<<0<<endl;
		return 0;
	}
	REP(i,N){
		c[D[i]]++;
	}
	REP(i,100001){
		if(i==0)continue;
		if(c[i]>0&&c[i-1]==0){
			cout<<0<<endl;
			return 0;
		}
	}
	if(c[0]>=2){
		cout<<0<<endl;
		return 0;
	}
	LL ans=1;
	REP(i,100001){
		if(c[i]==0){
			break;
		}
		if(i==0)continue;
		REP(j,c[i]){
			ans*=c[i-1];
			ans%=MOD;
		}
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 1792
n,m = map(int,input().split())
l = []
r = []
for i in range(m):
    l_x,r_x = map(int,input().split())
    l.append(l_x)
    r.append(r_x)

if min(r[0::])-max(l[0::])+1 >= 1:
    print(min(r[0::])-max(l[0::])+1)
else:
    print(0)

Measured memory_bytes: 11760
pascal = Array.new(51){Array.new(51, 0)}
pascal[0][0] = 1
1.upto(50){|n|
    pascal[n][0] = pascal[n][n] = 1
        1.upto(n / 2){|r|
            pascal[n][r] = pascal[n][n - r] = pascal[n - 1][r - 1] + pascal[n - 1][r]
        }
    }

l, k = gets.chomp.split.map(&:to_i)
sum, x = 0, 1
while true
    if x <= l
        sum += 1
        1.upto(x / 2 + 1){|y|
            if x + y * (k - 1) <= l
                sum += pascal[x / 2 + 1][y]
            else
                break
            end
        }
    else
        break
    end
    x += 2
end
puts sum



Measured memory_bytes: 8908
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e17;
 
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
 
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;}



signed main()
{
	IOS();
	vector<int>ans;
	while(1){
		int S,X,Y;
		cin>>X>>Y>>S;
		if(S==0&&X==0&&Y==0)break;
		int res = -INF;
		rep(i,1,1000)rep(j,1,1000){
			int a = i,b = j;
			a = a * (100 + X) / 100;
			b = b * (100 + X) / 100;
			if(a+b!=S)continue;
			a = i;
			b = j;
			a = a * (100 + Y) / 100;
			b = b * (100 + Y) / 100;
			chmax(res,a+b);
		}
		ans.push_back(res);
	}
	for(auto e:ans){
		cout<<e<<endl;
	}
}



Measured memory_bytes: 3132
#include <iostream>
//#include <array>
#include <string>

int main()
{
    std::string a, b, c;
    long n;
    long sum = 0;
    std::cin >> n >> a >> b >> c;
    for (long i = 0; i < n; i++) {
        if (!(a.at(i) == b.at(i) && b.at(i) == c.at(i))) {
            if (a.at(i) == b.at(i) || b.at(i) == c.at(i) || c.at(i) == a.at(i)) {
                sum += 1;
            } else {
                sum += 2;
            }
        }
    }
    std::cout << sum << std::endl;
    return 0;
}

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

int main()
{
	string S,A;

	cin >> S;

	int s = S.size(),a[10];

	for (int i = 0; i < s; i++) {
		a[i] = 0;
		if (S[i] != 'B') {
			a[i] = 1;
		}
		else if (S[i] == 'B'&& i > 0) {
			for (int ii = i - 1; ii >= 0; ii--) {
				if (a[ii]) {
					a[ii] = 0;
					break;
				}
			}
		}
	}

	for (int i = 0; i < s; i++) {
		if (a[i]) {
			A += S[i];
		}
	}

	cout << A;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int s;
    scanf("%d", &s);

    int x = s / 100; //上2桁
    int y = s % 100; //下2桁

    if ((1 <= x && x <= 12) && (1 <= y && y <= 12)){
        printf("%s\n", "AMBIGUOUS");
    }
    else if ((x == 0 || 13 <= x) && (1 <= y && y <= 12)){
        printf("%s\n", "YYMM");
    }
    else if ((1 <= x && x <= 12) && (y == 0 || 13 <= y)){
        printf("%s\n", "MMYY");
    }
    else {
        printf("%s\n", "NA");
    }

    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
int c[101];
void cxk(int i,int j){if(c[i]<j)puts("Impossible"),exit(0);}
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n=gi(),d=0,a;
	for(int i=1;i<=n;++i)++c[a=gi()],d=std::max(d,a);
	for(int i=d;i>=d+1>>1;--i)cxk(i,2-(i*2==d));
	for(int i=1;i<d+1>>1;++i)if(c[i])puts("Impossible"),exit(0);
	if(~d&1){if(c[d>>1]>1)puts("Impossible"),exit(0);}
	else{if(c[d+1>>1]>2)puts("Impossible"),exit(0);}
	puts("Possible");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2) % mod;
}
/*--------Library Zone!--------*/

int n, ba, b, a, ans;
signed main() {
	cin >> n;
	rep(i, n) {
		string s; cin >> s;
		if (s[0] == 'B' && s.back() == 'A')ba++;
		else if (s[0] == 'B')b++;
		else if (s.back() == 'A')a++;
		rep(j, s.size() - 1) {
			if (s[j] == 'A' && s[j + 1] == 'B')ans++;
		}
	}
	if (a + b) {
		cout << ans + ba + min(a, b) << endl;
	}
	else {
		cout << ans + max(0LL, ba - 1) << endl;
	}
}

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

using namespace std;

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

typedef long long ll;
typedef vector<int> vi;

int main(){
    ll n;
    cin >> n;
    ll ans = n-1;
    
    for(ll i = 1; i <= sqrt(n); i++){
        if(i*(n/i) == n){
            ans = min(ans, i+(n/i));
            if(i != 1 && (n/i) != 1){
                ans = ans - 2;
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  int n,k;
  string s;
  cin>>n>>s>>k;
  --k;
  rep(i,n){
    if(s[i]!=s[k])s[i]='*';
    }
  cout<<s<<endl;

    return 0;
}


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

int main() {
  int N, n, digit=0, pow=1, num=0;
  cin >> N;
  for(n=N; n>0; n/=10) {
    pow *= 10;
    ++digit;
  }
  if(digit%2) {
    num = -(pow-1-N);
    pow *= 10;
  }
  num += (pow-1)/11;
  cout << num << endl;
  return 0;
}

Measured memory_bytes: 256
#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()

using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;

int main() {
  string s, t;
  cin >> s >> t;

  sort(all(s)), sort(all(t));
  reverse(all(t));
  string res = (s < t) ? "Yes" : "No";

  cout << res << endl;
}

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

int main()
{
    int n;
    cin >> n;
    cout << (1 + n) * n / 2;
    return 0;
}


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

int main() {
    char str[1001] = "";
    cin >> str;
    for (int i = 0; str[i] != '\0'; i++) {
        if ('D' <= str[i] && str[i] <= 'Z') {
            str[i] -= 3;
        } else if ('A' <= str[i] && str[i] <= 'C') {
            str[i] += 23;
        }
        cout << str[i];
    }
    cout << endl;
}

Measured memory_bytes: 0
from itertools import accumulate

n = int(input())
a = list(map(int, input().split()))

a.sort()

acc = list(accumulate(a))

ans = 1
for i in range(n - 2, -1, -1):
    if acc[i] * 2 >= a[i+1]:
        ans += 1
    else:
        break

print(ans)


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

int main() {
  string s,t;
  cin >> s >> t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end(), greater<char>());
  if(s < t)
  cout << "Yes" << endl;
  else
  cout << "No" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdlib>
using namespace std;
int main(void){
	string s;cin>>s;
	int leng=(int)(s.length());
	int absmin=1000;
	for (int i=0 ; i<leng-2 ; i++){
		string ss;
		ss+=s[i];
		ss+=s[i+1];
		ss+=s[i+2];
		int a=stoi(ss);
		if (absmin>abs(a-753))absmin=abs(a-753);
	}
	cout<<absmin;
}

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

using namespace std;

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

int const MOD = 1e5;

int H, W;
vector<string> G;

bool able(int i, int j, int piece) {
  return G[i][j] == "JOI"[piece] || G[i][j] == '?';
}

bool goodFlag(int bitJO, int j, int piece) {
  return (bitJO >> j & 1) && piece == 2;
}

int main() {

  cin >> H >> W;
  G.resize(H);
  rep(i, H) {
    cin >> G[i];
  }

  // dp[??´??????????????????????????????]["JO"???????????§???????????????????¨???¶][??´??????'J'???] := ??????????????´????????°
  static int dp[2][1<<20][2];
  dp[0][0][0] = 1;

  int (*curr)[2] = dp[0];
  int (*next)[2] = dp[1];

  rep(i, H) {

    rep(j, W) {
      // ?¨???¶?????´?????¨??????????????????????????§???????????§?????????
      rep(i, 1<<20) rep(j, 2) next[i][j] = 0;
      rep(bitJO, 1 << W) {
        rep(isJ, 2) {
          if(!curr[bitJO][isJ]) continue;
          rep(piece, 3) {
            int nBitJO = bitJO & ~(1 << j), nIsJ = piece == 0;
            if(!able(i, j, piece)) continue;  // ??????????????????
            if(goodFlag(bitJO, j, piece)) continue;
            if(isJ == 1 && piece == 1) nBitJO |= 1 << (j - 1);  // "JO"???????????§???????????¨???"JO"?????????????¨???¶
            next[nBitJO][nIsJ] += curr[bitJO][isJ];
            if(next[nBitJO][nIsJ] >= MOD) next[nBitJO][nIsJ] -= MOD;
          }
        }
      }
      swap(curr, next);
    }

    // ?¨???¶?????´?????¨??????????????????????????§????¬????????????????????\??????????
    rep(S, 1 << W){
      curr[S][0] += curr[S][1];
      if(curr[S][0] >= MOD) curr[S][0] -= MOD;
      curr[S][1] = 0;
    }

  }

  int ans = 1; rep(i, H) rep(j, W) if(G[i][j] == '?') (ans *= 3) %= MOD;
  int sum = 0; rep(S, 1 << W) (sum += curr[S][0]) %= MOD;
  cout << (ans - sum + MOD) % MOD << endl;

  return 0;
}

Measured memory_bytes: 19552
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int h = sc.nextInt();
    int w = sc.nextInt();
    String[][] data = new String[h][w];
    int[] H = new int[h];
    int[] W = new int[w];

    for (int i = 0; i < h; i++) {
      String s = sc.next();
      for (int j = 0; j < w; j++) {
        data[i][j] = s.substring(j,j+1);
      }
    }

    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        if (data[i][j].equals("#")) {
          H[i]++;
        }
      }
    }

    for (int j = 0; j < w; j++) {
      for (int i = 0; i < h; i++) {
        if (data[i][j].equals("#")) {
          W[j]++;
        }
      }
    }

    // for (int i = 0; i < w; i++) {
    //   System.out.println(H[i]+"   "+W[i]);
    // }

    for (int i = 0; i < h; i++) {
      if (H[i] == 0) continue;
      for (int j = 0; j < w; j++) {
        if (W[j] == 0) continue;
      System.out.print(data[i][j]);
      }
      System.out.println("");
    }
  }

}


Measured memory_bytes: 25812
/*
  Contest 068
  A - ABCxxx
  Rakesh Kumar --> 01/09/2020
 */

#include <bits/stdc++.h>

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0); std::cout.tie(0);
    int n = 0;
    std::cin >> n;
    std::cout << "ABC" << n << std::endl;

    return 0;
}


Measured memory_bytes: 3552
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n,m,c;
	cin>>n>>m>>c;
	int b[m];
	rep(i,m)cin>>b[i];
	int a;
	int ans=0;
	rep(i,n){
		int sum=0;
		rep(j,m){
			cin>>a;
			sum+=a*b[j];
		}
		if(sum+c>0)ans++;
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = LONG_LONG_MAX;
const ll MINF = LONG_LONG_MIN;
const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<ll, vector<ll>, greater<ll>> PQ_ASK;
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}

    mint &operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }

    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }

    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }

    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod - 2);
    }

    mint &operator/=(const mint a) {
        return (*this) *= a.inv();
    }

    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

int main() {

    ll n;
    cin >> n;
    bitset<100> d(n);

    int max_digit = 0;

    for (int i = 100; i >= 0; i--) {
        if (d[i]) {
            max_digit = i;
            break;
        }
    }
    vector<vector<mint>> dp(3, vector<mint>(100, 0));
    dp[0][max_digit] = 1, dp[1][max_digit] = 1;

    for (int i = max_digit - 1; i >= 0; i--) {
        if (d[i] == 0) {
            dp[0][i] = dp[0][i + 1] + dp[1][i + 1];
            dp[1][i] = dp[1][i + 1];
            dp[2][i] = dp[1][i + 1] + dp[2][i + 1] * 3;
        } else {
            dp[0][i] = dp[0][i + 1];
            dp[1][i] = dp[0][i + 1] + dp[1][i + 1];
            dp[2][i] = dp[1][i + 1] * 2 + dp[2][i + 1] * 3;
        }
    }

    cout << (dp[0][0] + dp[1][0] + dp[2][0]).x << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import deque
import sys
input=sys.stdin.readline
h,w=map(int,input().split())
d=deque()
dc=0
b=[]
for i in range(h):
  t=[]
  s=input()
  for j in range(w):
    if s[j]=="#":d.append((i,j));dc+=1;t.append(1)
    else:t.append(0)
  b.append(t)
count=0
while dc!=0:
  ld=dc
  dc=0
  for i in range(ld):
    x=d.popleft()
    if x[0]<h-1:
      if b[x[0]+1][x[1]]==0:b[x[0]+1][x[1]]=1;d.append((x[0]+1,x[1]));dc+=1
    if 0<x[0]:
      if b[x[0]-1][x[1]]==0:b[x[0]-1][x[1]]=1;d.append((x[0]-1,x[1]));dc+=1
    if x[1]<w-1:
      if b[x[0]][x[1]+1]==0:b[x[0]][x[1]+1]=1;d.append((x[0],x[1]+1));dc+=1
    if 0<x[1]:
      if b[x[0]][x[1]-1]==0:b[x[0]][x[1]-1]=1;d.append((x[0],x[1]-1));dc+=1
  count+=1
print(count-1) 


Measured memory_bytes: 102364
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Linq;
using static System.Math;

class MainClass
{

    public static void Main(string[] args)
    {
        var x = LnLng();
        var a = (x % 500);
        var n500 = x / 500*1000;
        
        var n5 = a / 5*5;
        Console.WriteLine(n500 + n5);
    }
   

public static long Gcd(long a, long b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } }
    public static int Gcd(int a, int b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } }
    public static int[] LnInts() { var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new int[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = int.Parse(vs[i]); return ins; }
    public static int LnInt() { var vs = Console.ReadLine().Trim(); return int.Parse(vs); }
    public static long[] LnLngs() { var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new long[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = long.Parse(vs[i]); return ins; }
    public static long LnLng() { var vs = Console.ReadLine().Trim(); return long.Parse(vs); }
    public static string[] LnStrs() { var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); return vs; }
    public static string LnStr() { var vs = Console.ReadLine().Trim(); return vs; }
}



Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,j,n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(), i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9 + 7;
 
typedef long long i64;
typedef pair<int, int> pi;
 
template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;
 
i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcm(i64 n, i64 m) {return (n / gcd(n, m) * m);}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

template <class T> class Dinic {
  private:
    struct Edge {
      int to, rev;
      T cap;

      Edge(int to, T cap, int rev) : to(to), cap(cap), rev(rev) {}
    };
    
    std::vector<std::vector<Edge>> graph;
    std::vector<int> level;
    std::vector<int> iter;

  	void bfs(int s) {
      level.assign(level.size(), -1);

      std::queue<int> que;
    	level[s] = 0;
      que.push(s);

      while(!que.empty()) {
        int v = que.front();
        que.pop();

        for(auto &e : graph[v]) {
          if(e.cap > 0 && level[e.to] < 0) {
						level[e.to] = level[v] + 1;
						que.push(e.to);
					}
				}
      }
    }

    T dfs(int v, int t, int f) {
      if(v == t) return f;

      for(int &i = iter[v]; i < graph[v].size(); ++i) {
        Edge &e = graph[v][i];

        if(e.cap > 0 && level[v] < level[e.to]) {
          int d = dfs(e.to, t, min(f, e.cap));
          if(d > 0) {
						e.cap -= d;
						graph[e.to][e.rev].cap += d;
            return d;
					}
        }
      }
      return 0;
    }

  public:
    Dinic(int v) {
      graph = std::vector<std::vector<Edge>>(v);
      level = std::vector<int>(v);
      iter = std::vector<int>(v);
  	}

    void add_edge(int from, int to, T cap) {
      graph[from].emplace_back(to, cap, graph[to].size());
      graph[to].emplace_back(from, 0, graph[from].size() - 1);
    }

    T max_flow(int s, int t) {
      T flow = 0;

      while(true) {
        bfs(s);

        if(level[t] < 0) return flow;
        iter.assign(iter.size(), 0);

        int f;
        while((f = dfs(s, t, std::numeric_limits<T>::max())) > 0) flow += f;
      }
    }
};
 
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int v, e;
  cin >> v >> e;
  Dinic<int> dinic(v);
  rep(i, 0, e) {
    int a, b, c;
    cin >> a >> b >> c;
    dinic.add_edge(a, b, c);
  }

  cout << dinic.max_flow(0, v - 1) << endl;
}


Measured memory_bytes: 3244
#include<stdio.h>

int main(){
	int i;
	int j;
	int k;
	int tmp;
	int x[2];
	scanf("%d %d %d",&x[0],&x[1],&x[2]);
	for(i=0;i<=2;i++){
		for(j=0;j<2;j++){
			if(x[j]>x[j+1]){
				
				tmp=x[j];
				x[j]=x[j+1];
				x[j+1]=tmp;
				
			}
		}
		
	}

		printf("%d %d %d\n",x[0],x[1],x[2]);
	
	
	return 0;

	
}

Measured memory_bytes: 2620
//Zory-2020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef __int128 ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FR first
#define SE second
#define MP make_pair
#define PB push_back
#define vc vector
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bin(x) (1ll<<(x))
#define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
#define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
#define Debug printf("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define debug(x) cerr<<#x<<'='<<x<<endl
#define mem(x,val) memset(x,val,sizeof x)
namespace mine
{
    ll qread()
    {
        ll ans=0,f=1;char c=getchar();
        while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
        while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
        return ans*f;
    }
    void write(ll num){if(num<0) putchar('-'),num=-num;if(num>=10) write(num/10);putchar('0'+num%10);}
    void write1(ll num){write(num);putchar(' ');}
    void write2(ll num){write(num);putchar('\n');}
    template<typename T>inline bool chmax(T&a,const T&b){return a<b?a=b,1:0;}
    template<typename T>inline bool chmin(T&a,const T&b){return a>b?a=b,1:0;}
    ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
    bool IN(ll x,ll l,ll r){return l<=x and x<=r;}

    const int INF=0x3f3f3f3f;
    const int MOD=1e9+7;
    int mm(const int x){return x>=MOD?x-MOD:x;}
    template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
    ll qpower(ll x,ll e,int mod=MOD){ll ans=1;while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
    ll invm(ll x){return qpower(x,MOD-2);}
    const int N=1e3+10;

    int C[N][N],f[100][N];
    void main()
	{
        C[0][0]=1;fo(i,1,N-1){C[i][0]=1;fo(j,1,i)C[i][j]=mm(C[i-1][j-1]+C[i-1][j]);}
        int n=qread(),k=qread();f[0][n]=1;
        fo(id,1,k)
        {
            int a=qread();
            fo(i,0,n) fo(t,0,i)
                add(f[id][i-t],1ll*f[id-1][i]* C[i][t]%MOD*C[n-t][n-a]%MOD );
        }
        write(f[k][0]);
	}
};//(ans+MOD)%MOD
signed main()
{
    srand(time(0));
    mine::main();
}


Measured memory_bytes: 4352
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	value, _ := strconv.Atoi(sc.Text())
	return value
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Scan()
	S := sc.Text()
	head, _ := strconv.Atoi(S[:2])
	tail, _ := strconv.Atoi(S[2:])
	if head > 12 || head == 0 {
		if tail > 12 || tail == 0 {
			fmt.Printf("NA")
		} else {
			fmt.Printf("YYMM")
		}
	} else {
		if tail > 12 || tail == 0 {
			fmt.Printf("MMYY")
		} else {
			fmt.Printf("AMBIGUOUS")
		}
	}
}

Measured memory_bytes: 640
package main

import (
	"fmt"
)

// bit全探索

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

	if k  % 2 == 0 {
		fmt.Println(-1)
		return
	}

	n := 7
	for i := 1 ; i <= int(1e6); i++ {
		if n% k == 0 {
			fmt.Println(i)
			return
		}
		n *= 10
		n += 7
		n %= k
	}
	fmt.Println(-1)
}



Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second

int n;
vector<int> e[100010];

int hashi[100010], hn;

char vis[100010];

void dfs(int x){
	vis[x]=1;
	int ic = 0;
	for(int y:e[x]) if(e[y].size() != 1u){
		++ic;
		if(!vis[y]) dfs(y);
	}
	if(ic >= 3){ puts("-1"); exit(0); }
	if(ic <= 1){
		hashi[hn++] = x;
	}
}

int cp[100010];
int np[100010], npp;

void Make(int x){
	int lc = 0;
	vis[x] = 1;
	int nxt = -1;
	for(int y:e[x]) if(!vis[y]){
		if(e[y].size() == 1u) ++lc;
		else nxt = y;
	}
	for(int i=1; i<=lc; ++i) np[npp+i] = npp+i+1;
	np[npp + lc + 1] = npp + 1;
	npp += lc + 1;
	if(nxt != -1) Make(nxt);
	else if(lc >= 1) swap(np[n-1], np[n]);
}

void Prep(){
	fill(vis+1, vis+n+1, 0); npp=0;
}
void Upd(){
	for(int i=1; i<=n; ++i){
		if(cp[i] < np[i]) break;
		else if(cp[i] > np[i]){
			for(int j=i; j<=n; ++j) cp[j]=np[j];
			break;
		}
	}
}

int main()
{
	read(n);
	if(n == 2){ puts("1 2"); return 0; }
	for(int i=1; i<n; ++i){
		int a, b; read(a, b);
		e[a].pb(b); e[b].pb(a);
	}
	
	for(int i=1; i<=n; ++i) if(e[i].size() != 1u){ dfs(i); break; }
	if(hn > 2){ puts("-1"); return 0; }
	
	for(int i=1; i<=n; ++i) cp[i]=n+1-i;
	for(int a=0; a<hn; ++a){
		Prep(); Make(hashi[a]); Upd();
		for(int p:e[hashi[a]]) if(e[p].size() == 1u){
			Prep(); Make(p); Upd();
			break;
		}
	}
	
	for(int i=1; i<=n; ++i) printf("%d ", cp[i]);
	return 0;
}


Measured memory_bytes: 9472
#include <stdio.h>
#include <string.h>

int main(void){
   char s1[]="SUN";
   char s2[]="MON";
   char s3[]="TUE";
   char s4[]="WED";
   char s5[]="THU";
   char s6[]="FRI";
   char s7[]="SAT";
   char s[8];
  
   scanf("%s",&s);
  
   if(strcmp(s,s1) ==0){
      printf("7");
   } 
   else if(strcmp(s,s2) ==0){
      printf("6");
   } 
   else if(strcmp(s,s3) ==0){
      printf("5");
   } 
   else if(strcmp(s,s4) ==0){
      printf("4");
   } 
   else if(strcmp(s,s5) ==0){
      printf("3");
   } 
   else if(strcmp(s,s6) ==0){
      printf("2");
   } 
   else if(strcmp(s,s7) ==0){
      printf("1");
   } 
   
   else{
    printf("0");
   }

   return 0;
}

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

#define MOD 1000000007
#define pb push_back
#define all(v) (v.begin(), v.end());
#define ff first
#define ss second
#define db(x) cerr << #x << " = "  << x << '\n'
#define ooo cerr << "---------------------\n"

using namespace std;

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

void goooooo()
{
	int n, x;
	cin >> n >> x;
	vector<int> a(n + 3, 0), b(n + 3, 0);
	int minn = 10000000;
	for(int i = 1; i <= n; i ++)
	{
		cin >> a[i] >> b[i];
		if(b[i] <= x)
			minn = min(minn, a[i]);
	}
	if(minn == 10000000)
		cout << "TLE";
	else
	cout << minn;
}

int main()
{
	int abcdefghijklmnopqrstuvwxyz = 1;
//	cin >> abcdefghijklmnopqrstuvwxyz;
	for(;abcdefghijklmnopqrstuvwxyz;abcdefghijklmnopqrstuvwxyz --)
		goooooo();
	getchar();
	getchar();
}

Measured memory_bytes: 256
/*
 * short          2^15-1 ~ 3e4
 * int, long x86  2^31-1 ~ 2e9
 * long long      2^63-1 ~ 9e18
 */
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define int long long
#define fr(a, b) for (int a = 0; a < b; ++a)
using namespace std; typedef long long ll; const int inf = numeric_limits<int>::max(); void print() {cerr << endl;}
template<typename T, typename... Ts> void print(T&&a, Ts&&...etc) {cerr << a << ' '; print(etc...);}
template<typename T, typename U> ostream& operator<<(ostream& s, const pair<T,U>&p) {s << "<" << p.x << ", " << p.y << ">"; return s;} // ver. 2020-02-17
template<typename T> ostream& operator<<(ostream& s, const vector<T>&v) {s << "["; for (auto &x : v) s << x << ", "; if (!v.empty()) s << "\b\b"; s << "]"; return s;}
struct io{io(){ios_base::Init i; ios_base::sync_with_stdio(0); cin.tie(0);}}io;

int solve() {
    int n;
    cin >> n;
    vector<int> a(n+1);
    fr(i, n+1) cin >> a[i];

    if (a[0] != 0) {
        if (a[0] == 1 && n == 0) {
            return 1;
        }
        return -1;
    }

    vector<int> max_w(n+1);
    max_w[n] = a[n];
    for (int i = n-1; i >= 0; --i) {
        max_w[i] = max_w[i+1] + a[i];
    }
    print(a);
    print(max_w);

    int inner = 1;
    int total = 1;
    for (int i = 1; i < n+1; ++i) {
        inner *= 2;
        inner = min(inner, max_w[i]);
        total += inner;
        inner -= a[i];
        if (i == n) {
            if (inner != 0) {
                return -1;
            }
        } else {
            if (inner <= 0) {
                return -1;
            }
        }
    }
    return total;
}

signed main() {
    cout << solve() << endl;
}


Measured memory_bytes: 4780
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
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 = 1e9;
const LL LLINF = 1e16;

int main(){
    int t,d,l;
    cin >> t >> d >> l;
    while(t > 0){
        vector<int> x(t);
        rep(i, t) cin >> x[i];
        vector<int> ans(t+d+2, 0);
        rep(i, t){
            if(x[i] >= l){
                ans[i]++;
                ans[i+d]--;
            }
        }
        rep(i, t) ans[i+1] += ans[i];
        int a = 0;
        // rep(i, t) cout << ans[i] << endl;
        rep(i, t-1) if(ans[i] > 0) a++;
        cout << a << endl;
        cin >> t >> d >> l;
    }
}


Measured memory_bytes: 4556
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main(void) {
  long long int n, k;
  scanf("%lld %lld", &n, &k);

  long long int a = n % k;
  long long int b = -(a - k);

  if (a < b) {
    printf("%lld\n", a);
  } else {
    printf("%lld\n", b);
  }

  return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f=true){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f=true){cout<<(f?"YES":"NO")<<endl;}
#define ANS(a) cout<<a<<endl

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int a,b; cin >>a>>b;
    cout << a*b/2 << endl;
}


Measured memory_bytes: 256
def examA():
    N = LI()
    N.sort()
    if N==[1,4,7,9]:
        print("YES")
    else:
        print("NO")
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math,random
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examA()

"""

"""

Measured memory_bytes: 4824