akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int n,m;
string st;
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
    	cin>>st;
    	cout<<st<<"\n"<<st<<"\n";
    }
	return 0;
}

Measured memory_bytes: 256
import sys

def solve():
    input = sys.stdin.readline
    N = input().strip("\n")
    K = int(input())
    dig = len(N)
    DP = [[0] * (K + 1) for _ in range(dig)]
    DP[0][0] = 1
    DP[0][1] = int(N[0]) - 1
    for i in range(1, dig):
        DP[i][1] = 9
        if N[i] != "0": 
            DP[i][0] = DP[i-1][0] + 1
            if DP[i-1][0] <= K: DP[i][DP[i-1][0]] += 1
            if DP[i-1][0] <= K - 1: DP[i][DP[i-1][0] + 1] += int(N[i]) - 1     
        else: DP[i][0] = DP[i-1][0]
        for j in range(1, K): DP[i][j+1] += DP[i-1][j] * 9
        for j in range(1, K + 1): DP[i][j] += DP[i - 1][j]
    if DP[dig - 1][0] == K: DP[dig - 1][K] += 1
    print(DP[dig - 1][K])
    #print(DP)

            
    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 3064
#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 complex<ld> cd;

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

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

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

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

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

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

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

    int N; cin >> N; int data[N];
    F0R(i, N) cin >> data[i];
    int best = 0;
    F0R(i, N) {
        int cur; cin >> cur; best += max(data[i] - cur, 0);
    }
    cout << best << endl;

    return 0;
}

// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 256
// **** WHEN THE GOING GETS TOUGH, THE TOUGH GETS GOING. ****

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define ordered_set tree < ll ,  null_type ,  less<ll> ,  rb_tree_tag ,  tree_order_statistics_node_update >
//added two more functions to set
//(1)*(set.find_by_order(k))[kth element in the sorted set] 
//(2)set.order_of_key(k)[count of elements strictly less than k]

typedef vector< int > vi;
typedef vector< ll > lvi;
typedef vector< vi > vvi;
typedef vector< lvi > lvvi;
typedef pair< int,int > ii;
typedef pair< ll,ll > lii;
typedef vector<ii> vii;
typedef vector<lii> lvii;

#define min_prq(t) priority_queue<t,vector<t>,greater<t>>
#define max_prq(t) priority_queue<t>
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)//remember i is an iterator
#define present(c,x) ((c).find(x) != (c).end())//for sets,maps,multimaps
#define cpresent(c,x) (find(all(c),x) != (c).end())//for vectors
#define tc(t) int (t); cin>>(t);while((t)--)
#define ff first
#define ss second
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " is " << a << endl;
	err(++it, args...);
}

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
#define mod 1000000007
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------

ll mod_sum() { return 0LL; }
template<typename T, typename... Args>
T mod_sum(T a, Args... args) { return ((a + mod_sum(args...))%mod + mod)%mod; }

ll mod_product() { return 1LL; }
template<typename T, typename... Args>
T mod_product(T a, Args... args) { return (a*mod_product(args...))%mod; }
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------

ll getmin(ll h,ll m)
{
	return h*60 + m;
}

signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);	
	ll h,m;
	cin>>h>>m;
	ll m1=getmin(h,m);
	cin>>h>>m;
	ll m2=getmin(h,m);
	ll k;
	cin>>k;
	cout<<max(0LL,m2-k-m1)<<endl;
	return 0;
}	

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int a[200010];
int flag;
int n,m;
int main() {
	scanf("%d%d",&n,&m);
	flag=0;
	int u,v;
	for(int i=1; i<=n; i++)
		a[i]=0;
	for(int i=1; i<=m; i++) {
		scanf("%d%d",&u,&v);
		if(flag)
			continue;
		if(u==1) {
			if(a[v]) {
				flag=1;
			}
			a[v]=1;
		}

		else if(v==n) {
			if(a[u]) {
				flag=1;
			}
			a[u]=1;
		}

	}
	if(flag)
		printf("POSSIBLE\n");
	else printf("IMPOSSIBLE\n");

	return 0;
}



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

int S[100];
int top;

void push(int x){
    //printf("push %d\n",x);
    top++;
    S[top] = x;
}

int pop(){
    //printf("pop %d\n",S[top]);
    top--;
    return S[top+1];
    
}

int main(void){
    top = 0;
    char x[100];
    int a, b;
    while(scanf("%s",x) != EOF){
        //printf("%s\n",x);
        if(x[0] == '+'){
            a = pop();
            b = pop();
            push(a+b);
        }
        else if(x[0] == '-'){
            a = pop();
            b = pop();
            push(b-a);
        }
        else if(x[0] == '*'){
            a = pop();
            b = pop();
            push(a*b);
        }
        else{
            push(atoi(x));
        }
    }
    printf("%d\n",pop());
    return 0;
}


Measured memory_bytes: 2112
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner reader = new Scanner(System.in);
        int[] num = {reader.nextInt(), reader.nextInt(), reader.nextInt()};
        Arrays.sort(num);
        
        System.out.println(num[0] + " " + num[1] + " " + num[2]);
    }
}


Measured memory_bytes: 26188
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>
#include <cmath>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBAG = false;


int main(){

    ll N;
    cin >> N;

    vector<ll> v(N);
    for(int i = 0; i < N; i++) cin >> v[i];

    if(v[0] > 0 ){
        cout << -1 << endl;
        return 0;
    }

    ll ans = 0;
    for(int i = N - 1; i >= 1; i--){
        if(v[i] - v[i-1] == 1) ans ++;
        else if(v[i] - v[i-1] <= 0) ans += v[i];
        else if(v[i] - v[i-1] >= 2){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#132
#入力（1次元）
n = int(input())
p = list(map(int, input().split()))

count = 0

#判定
for i in range(0,n - 2):
    if(p[i] < p[i + 1] and p[i + 1] < p[i + 2]):
        count = count + 1 
    elif(p[i] > p[i + 1] and p[i + 1] > p[i + 2]):
        count = count + 1

print(count)


Measured memory_bytes: 3060
#include <iostream>
int main(void)
{
  int n;
  std::cin >> n;
  int* a = new int[n];
  int r = 0;
  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
  }
  int min = 1000001, max = -1000001;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    sum += a[i];
    if (min > a[i]) min = a[i];
    if (max < a[i]) max = a[i];
  }
  std::cout << min << " " << max << " " << sum << std::endl;
  delete a;
}

Measured memory_bytes: 1236
#include<iostream>
#include<string>
#include<cstdio>
#include <cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
    int N; cin >> N;
    int a[200200], b[200200];
    rep(i, N) cin >> a[i];
    rep(i, N) cin >> b[i];
    int ans = 0;
    for(int k = 28; k >= 0; k--) {
        rep(i, N) {
            a[i] %= (1 << (k + 1));
            b[i] %= (1 << (k + 1));
        }
        sort(a, a + N);
        sort(b, b + N);
        int cnt = 0;
        rep(i, N) {
            cnt += lower_bound(b, b + N, (1 << (k + 1)) - a[i]) - lower_bound(b, b + N, (1 << k) - a[i]);
            cnt %= 2;
            cnt += lower_bound(b, b + N, 4 * (1 << k) - a[i]) - lower_bound(b, b + N, 3 * (1 << k) - a[i]);
            cnt %= 2;
        }
        if(cnt % 2 == 1) ans += (1 << k);
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
// https://atcoder.jp/contests/dp/tasks/dp_a
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

#define FOR(i, n) for (int i = 0; i < n; i++)
#define EACH(i, n) for (auto &i: n)

int main() {
  int n;

  cin >> n;

  vector<int> h(n);
  vector<int> dp(n, 0);
  FOR(i, n) {
    cin >> h[i];
  }

  dp[1] = abs(h[0] - h[1]);
  for (int i = 2; i < n; i++) {
    dp[i] = min(
      dp[i - 2] + abs(h[i - 2] - h[i]),
      dp[i - 1] + abs(h[i - 1] - h[i])
    );
  }
  cout << dp[n - 1] << endl;

  return 0;
}


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

int compare_long(const void *a, const void *b)
{
	long *A = (long *)a;
	long *B = (long *)b;
	if (*A < *B) return 1;
	if (*A > *B) return -1;
	return 0;
}

int main(void)
{
	//変数の宣言
	int n,kosu;
	int a[1010];
	static long int suretu[600000];
	int njou;
	long int njou2;
	static int bl[600000];
	int keta[50];
	
	//よく使う変数
	int i,j,k,l;
	int flag=0;
	long int ans=0;
	int count=0;
	long int temp,temp1,temp2;
	int max,min;
	int len;
	//データの読み込み
	
	scanf("%d %d",&n,&kosu);
	
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	//実際の処理
	
	len=0;
	for(i=0;i<n;i++){
		temp=0;
		for(j=i;j<n;j++){
			temp=temp+a[j];
//			printf("j=%d,a[j]=%d,temp=%d\n",j,a[j],temp);
			suretu[len]=temp;
			len++;
		}
	}
	
//	for(i=0;i<len;i++){
//		printf("%d ",suretu[i]);
//	}
//	printf("\n");
	
	qsort(suretu, len, sizeof(long int), compare_long);
	
//	for(i=0;i<len;i++){
//	printf("%d ",suretu[i]);
//	}
//	printf("\n");
	
	njou=0;
	temp=1;
	while(flag==0){
		if(suretu[kosu-1]<temp*2){
			flag=1;
		}else{
			temp=temp*2;
			njou++;
		}
	}
	
//	printf("njou=%d\n",njou);
	
	njou2=1;
	for(i=0;i<njou;i++){
		njou2=njou2*2;
	}
	
	keta[njou]=1;
	for(i=0;i<len;i++){
		if(suretu[i]>=njou2){
			bl[i]=1;
		}else{
			len=i;
			break;
		}
	}
	
	temp=0;
	for(i=njou-1;i>=0;i--){
		count=0;
		for(j=0;j<len;j++){
			if(bl[j]==1){
				temp=suretu[j];
				for(k=0;k<i;k++){
					temp=temp/2;
				}
				if(temp%2==1){
					count++;
				}
			}
		}
//		printf("kosu=%d,count=%d\n",kosu,count);
		if(count>=kosu){
//			printf("count>=kosu\n");
			keta[i]=1;
			for(j=0;j<len;j++){
				if(bl[j]==1){
					temp=suretu[j];
					for(k=0;k<i;k++){
						temp=temp/2;
					}
					if(temp%2==0){
						bl[j]=0;
					}
				}
			}
		}else{
			keta[i]=0;
		}
		
//		for(j=0;j<len;j++){
//			printf("%2d ",bl[j]);
//		}
//		printf("\n");
//		printf("keta[%d]=%d count=%d\n",i,keta[i],count);
	}
	
	for(i=njou;i>=0;i--){
//		printf("keta[%d]=%d\n",i,keta[i]);
		if(keta[i]==1){
			ans++;
		}
		if(i!=0) ans=ans*2;
	}
	
//	printf("計算部分終了\n");
	//出力
	
	
	printf("%ld",ans);
	
//	printf("結果の出力終了\n");
	
	return 0;
	
}



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

main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    long long i,j,k,l,m,n,o,p;
 string s;
 cin>>s;
 l=s.size();
 cout<<s;
 if(s[l-1]=='s')cout<<"es"<<endl;
 else cout<<"s"<<endl;
    return 0;
}


Measured memory_bytes: 3588
#include <iostream>
#include <string>
using namespace std;
struct Node {
    int id;
    int parent;
    int leftChild;
    int rightSibling;
    Node(): id(-1),parent(-1),leftChild(-1),rightSibling(-1){}
    Node(int id, int parent, int leftChild, int rightSibling) : id(id), parent(parent), leftChild(leftChild), rightSibling(rightSibling) {}
    friend std::ostream & operator<<(std::ostream & _stream, Node const & node) {
        _stream<<"node "<<node.id<<": parent = "<<node.parent << ", depth = " << node.leftChild<<" "<< node.rightSibling <<std::endl;
    }
};

int getNodeDepth(Node* node, int id) {
    if(!node || id<0) {
        return 0;
    }
    // 根到节点的距离
    int parent = node[id].parent;
    int length = 0;
    while (parent!=-1) { // 不为根节点
        length++;
        parent = node[parent].parent;
    }
    return length;
}
string getNodeType(Node* node, int id) {
    if(!node || id<0) {
        return "";
    }
    // 节点类型：root/internal node/leaf
    if(node[id].parent == -1) {
        return string("root");
    }else if(node[id].leftChild == -1) {
        return string("leaf");
    }else {
        return string("internal node");
    }
}
string getChildList(Node* node, int id) {
    if(!node || id<0) {
        return "";
    }
    string result = string("[");
    int child = node[id].leftChild;
    if(child!=-1) {
        result+=to_string(child);
        int right = node[child].rightSibling;
        if(right!=-1)
            result+=", ";
        while (right != -1) {
            result+=to_string(right);
            right = node[right].rightSibling;
            if(right != -1)
                result+=", ";
        }

    }
    result+="]";
    return result;
}

int main() {

    int count = 0;
    cin >> count;
    if (count <= 0) {
        return 0;
    }
    Node *arr = (Node *) malloc(sizeof(Node) * count);
    for (int k = 0; k < count; ++k) {
        arr[k].leftChild = -1;
        arr[k].rightSibling = -1;
        arr[k].parent = -1;
    }
    for (int i = 0; i < count; ++i) {
        int childLength = 0;
        int id = 0;
        int childId = 0;
        cin >> id;
        arr[id].id = id;
        cin >> childLength;
        if (childLength == 0) {
            arr[id].leftChild = -1;
        } else {
            cin >> childId;
            arr[id].leftChild = childId;
            arr[childId].parent = id;
            childLength--;
            int newChildId = 0;
            while (childLength > 0) {
                cin >> newChildId;
                arr[childId].rightSibling = newChildId;
                arr[newChildId].parent = id;
                childId = newChildId;
                childLength--;
            }
            arr[childId].rightSibling = -1;
        }
    }
    for (int j = 0; j < count; ++j) {
        int nodeDepth = getNodeDepth(arr, j);
        string nodeType = getNodeType(arr, j);
        string childLists = getChildList(arr, j);
        cout << "node " << arr[j].id << ": parent = " << arr[j].parent << ", depth = " << nodeDepth << ", " << nodeType
             << ", " << childLists << endl;
    }
    return 0;
}


Measured memory_bytes: 5476
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
vector<int> comp;
vector<vector<int> > G;
void dfs(int pos, int pre) {
	comp.push_back(pos);
	for (int i : G[pos]) {
		if (i == pre) continue;
		dfs(i, pos);
	}
}
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	G.resize(N);
	vector<int> v(N);
	for (int i = 0; i < N; ++i) cin >> v[i];
	for (int i = 0; i < M; ++i) {
		int a, b;
		cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	vector<bool> vis(N);
	vector<int> all; int C = 0;
	long long ans = 0;
	for (int i = 0; i < N; ++i) {
		if (vis[i]) continue;
		comp.clear();
		dfs(i, -1);
		int opt = 1 << 30;
		for (int j : comp) {
			vis[j] = true;
			opt = min(opt, v[j]);
		}
		ans += opt;
		++C;
		for (int j : comp) {
			if (v[j] == opt) {
				opt = -1;
			}
			else {
				all.push_back(v[j]);
			}
		}
	}
	sort(all.begin(), all.end());
	if (C == 1) cout << 0 << endl;
	else if (all.size() < C - 2) cout << "Impossible" << endl;
	else {
		for (int i = 0; i < C - 2; ++i) ans += all[i];
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 7416
// #include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <iterator>
#include <functional>
#include <limits>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <stack>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define trace(x) cerr << #x << ": " << x << " " << endl;
 
typedef int64_t ll;
 
#define endl '\n'
#define int ll
ll mod=1e9+7;
ll mod1=1e9+5;
 
ll power(ll a,ll b)
{
    if(b==0) return 1;
    else if(b%2==0)
        return power((((a%mod)*(a%mod))%mod),b/2)%mod;
    else return ((a%mod)*(power((((a%mod)*(a%mod))%mod),b/2)%mod))%mod;
}
     
 //using namespace __gnu_pbds;
 //#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
//find_by_order(k)  returns iterator to kth element starting from 0;
//order_of_key(k) returns count of elements strictly smaller than k;
//erase,insert same as normal set
// mt19937 mrand(chrono::high_resolution_clock::now().time_since_epoch().count()); for randomized solution

int32_t main()
{
    IOS

    
    int a,b,c;
    cin>>a>>b>>c;
    swap(a,b);
    swap(a,c);
    cout<<a<<" "<<b<<" "<<c;
}       

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
    string str;
    int n;
    while(cin>>str){
        if(str=="-") break;
        cin>>n;
        for(int i=0; i<n; i++){
            int h;
            cin>>h;
            string cat=str.substr(0,h);
            str.erase(0,h);
            str+=cat;
        }
        cout << str << endl;
    }
}


Measured memory_bytes: 3220
/**
 *      author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *      created : 2019-12-01 20:49:30
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>

using namespace std;

using int64 = long long;
#define debug(_) cerr << #_ << ": " << (_) << '\n'
template<typename T> inline void chmin(T &a, T b) { if (a > b) a = b; return; }
template<typename T> inline void chmax(T &a, T b) { if (a < b) a = b; return; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& vec) { os << '{'; for (size_t i = 0; i < vec.size(); ++i) { os << vec[i]; if (i != vec.size() - 1) os << ','; } os << '}'; return os; }
template<typename T, typename U> ostream& operator<<(ostream& os, const pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }

constexpr int64 MOD = 1e9 + 7;

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

  int n; cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i] > i) {
      cout << 0 << endl;
      return 0;
    }
  }

  map<int, int64> mp;
  mp[0] = 3LL;

  int64 ans = 1LL;

  for (int i = 0; i < n; ++i) {
    ans *= mp[a[i]];
    --mp[a[i]];
    ++mp[a[i] + 1];
    ans %= MOD;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5 << 28, MOD = 1e9 + 7;

int a, b, c, d;
void input() { cin >> a >> b >> c >> d; }
void solve() {
  cout << max(0LL, (min(b, d) - max(a, c))) << endl;
  ;
  ;
}
signed main() {
  input();
  solve();
  return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

ll keta(ll a, ll b)
{
    int num_a = 0, num_b = 0;
    while (a)
    {
        num_a++;
        a /= 10;
    }
    while (b)
    {
        num_b++;
        b /= 10;
    }
    return max(num_a, num_b);
}

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

    ll ans = 1000;
    for (ll A = 1; A * A < N + 1; A++)
    {
        ll B;
        if (N % A == 0)
        {
            B = N / A;
        }
        ans = min(ans, keta(A, B));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
p = list(map(int,input().split()))

if p == sorted(p):
    print('YES')
else:
    ret = 'NO'
    is_sorted = False
    # 全通りの組み合わせをみて、昇順かどうか調べる
    for i in range(N-1):
        for j in range(i+1, N):
            # p[i]とp[j]より小さければ抜ける
            if p[i] < p[j]:
                continue
            else:
                k = p.copy()
                k[i], k[j] = k[j], k[i]

#             for l in range(N-1):
#                 if k[l+1] < k[l]:
#                     is_sorted = False
#                     break

            if k == sorted(p):
                ret = 'YES'
                is_sorted = True
                break
        if is_sorted:
            break

    print(ret)

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

int main() {
    int n;
    cin >> n;
    int a[n];

    for(int i = 0; i < n; i++){
        cin >> a[i];
    }

    int count = 0;
    
    int flag = 1;
    while(flag){
        flag = 0;
        for(int j = n-1; j >= 1; j--){
            if(a[j] < a[j-1]){
                int tmp;
                tmp = a[j];
                a[j] = a[j-1];
                a[j-1] = tmp;
                flag = 1;
                count++;
            }
        }
    }
    
    for(int i = 0; i < n-1; i++){
        cout << a[i] << " ";
    }

    cout << a[n-1] << endl;
    cout << count << endl;
}


Measured memory_bytes: 3124
/*
	- 20.3.2
	I - Coins
	Atcoder-Educational DP Contest-I - Coins
	20.3.2-Atcoder-Educational DP Contest-I - Coins- 
	- 
	-
	- 
*/
#include <bits/stdc++.h>
using namespace std;
double p[3000],f[3000][3000];
double ans=0;
int n;

int main()
{
	cin>>n;
	f[0][0]=1;
	for (int i=1;i<=n;++i)
	{
		cin>>p[i];
		f[i][0]=f[i-1][0]*(1-p[i]);
		for (int j=1;j<=i;++j)
			f[i][j]=f[i-1][j-1]*p[i]+f[i-1][j]*(1-p[i]);
	}
	for (int i=n/2+1;i<=n;++i)
		ans+=f[n][i];
	cout<<fixed<<setprecision(10)<<ans<<endl;
	return 0;
}

Measured memory_bytes: 68864
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
int main(){
    int n,dp[1001][1001];
    cin>>n;
    string x,y;
    rep(i,n){
        cin>>x>>y;
        rep(j,x.size()+1) rep(k,y.size()+1) dp[j][k]=0;
        rep(j,x.size()) rep(k,y.size()){
            if(x[j]==y[k]) dp[j+1][k+1]=max(max(dp[j][k]+1,dp[j+1][k]),dp[j][k+1]);
            else dp[j+1][k+1]=max(dp[j+1][k],dp[j][k+1]);
        }
        cout<<dp[x.size()][y.size()]<<endl;
    }
}


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



signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    int n;
    cin>>n;
    string s;
    cin>>s;
    int dp[n][n]={};
    int ans=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(dp[i][j]) continue;
            int cnt=0;
            while(i+cnt<j && j+cnt<n && s[i+cnt]==s[j+cnt]){
                cnt++;
            }
            ans = max(ans,cnt);
            for(int k=0;k<cnt;k++){
                dp[i+k][j+k] = cnt - k;
            }
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 97920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1'000'000'007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define REP(i, n) for(ll i=0; i<(ll)(n); i++)
#define REPD(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main(){
    ll n, m, k; cin >> n >> m >> k;
    vector<ll> a(n, 0), b(m, 0);
    REP(i, n)   cin >> a[i];
    REP(i, m)   cin >> b[i];
    ll bc=0, times=0;
    while(bc<m && times+b[bc]<=k) times += b[bc++];
    
    ll ac=0, res=bc;
    while(0<=bc){
        while(ac<n && times+a[ac]<=k){
            times += a[ac++];
        }
        res = max(ac+bc--, res);
        if(bc<0) break;    
        times -= b[bc];
    }
    cout << res << endl;
}


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

int main() {
	string a, b;
	cin >> a >> b;
	a += b;
	int x = stoi(a);
	int y = (int)sqrt(x);
	if (y*y == x)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
INF = (10 ** 9) + 7

N, K = map(int, input().split())
aLst = list(map(int, input().split()))

tmp1 = 0
tmp2 = 0

for i in range(N):
    for j in range(i + 1, N):
        if aLst[i] > aLst[j]:
            tmp1 += 1

for i in range(N):
    for j in range(N):
        if aLst[i] > aLst[j]:
            tmp2 += 1

ans = (tmp1 * (K)) + ((K * ((K - 1)) // 2) * tmp2)
print(ans % INF)

Measured memory_bytes: 3188
# import sys
# input = sys.stdin.readline

N, M = map(int, input().split())
s = [0] * M
c = [0] * M
for i in range(M):
    s[i], c[i] = map(int, input().split())
    s[i] -= 1


def check(x):
    if (len(str(x)) != N):
        return False
    for i in range(M):
        if(len(str(x))-1 < s[i]):
            return False
        if int(str(x)[s[i]]) != c[i]:
            return False
    return True


ans = -1
for x in range(1000):
    if (check(x)):
        ans = x
        break
print(ans)


Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;


    void calc()
    {
        cin = new Scanner();
        int[] N = cin.ArrayInt(3,0);
        Array.Sort(N);
        Console.WriteLine(N[0]+" "+N[1]+" "+N[2]);
    }


}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


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

using namespace std;
using ll = long long;

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define RS(N) resize(N)
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);

#define MOD 1000000007

void init();
void solve();

signed main()
{
	init();
	solve();
}

int fr[100];
int fc[100];
int H, W;
char m[100][100];

void init()
{
	cin >> H >> W;
	rep(i, H) {
		rep(j, W) {
			char c;
			cin >> c;
			m[i][j] = c;
			if (c == '#') {
				fr[i] = 1;
				fc[j] = 1;
			}
		}
	}
}

void solve()
{
	rep(i, H) {
		if (fr[i] == 0) continue;
		rep(j, W) {
			if (fc[j]) {
				cout << m[i][j];
			}
		}
		cout << endl;
	}
}





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

class Program
{
    static void Main(string[] args)
    {
        var line = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
        var N = line[0];
        var K = line[1];
        var max = ((N - 1) * (N - 2)) / 2;
        if ( K < 0 || max < K )
        {
            Console.WriteLine(-1);
        }
        else
        {
            var sabun = max - K;
            Console.WriteLine($"{(N-1)+sabun}");
            for (int i = 2; i <= N; ++i)
            {
                Console.WriteLine($"1 {i}");
            }
            if (sabun <= 0) return;
            for (int i = 2; i < N; ++i)
            {
                for (int j=i+1; j <= N;++j)
                {
                    Console.WriteLine($"{i} {j}");
                    if (--sabun <= 0) return;
                }
            }
        }
    }
}



Measured memory_bytes: 13396
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N,A,B = MI()
q = N // (A+B)
r = N % (A+B)
ans = q*A
if r <= A:
    ans += r
else:
    ans += A
print(ans)


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

bool Judge(int m, vector<int> A)
{
	int n = A.size();
	if(m == 0){
		return true;
	}
	if(n == 1){
	    if(m == A[0]){
	        return true;
	    }
	}else{
		int l = m - A.back();
		A.pop_back();
		if(Judge(m, A) || Judge(l, A)){
			return true;
		}
	}
	return false;
}

int main()
{ 
	int n, q; //n:??´??°???????????? q:???????????° 
	cin >> n;
	vector<int> A, M;
	for(int i = 0; i < n; i++){
		int a;
		cin >> a;
		A.push_back(a);
	}
	cin >> q;
	for(int i = 0; i < q; i++){
		int m;
		cin >> m;
		M.push_back(m);
	}
	for(int i = 0; i < q; i++){
		if(Judge(M[i], A)){
			cout << "yes" << endl;
		}else{
			cout << "no"  << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define m 1000000007
#define r(i,n) for(l i=0;i<n;i++)
#define B push_back
using namespace std;
typedef long l;
typedef vector<l> L;

vector<L> p;

l P(l i, l b) {
	l a = 1;
	r(n, 62) {
		if ((b >> n) % 2 == 1) {
			a *= p[i][n];
			a %= m;
		}
	}
	return a;
}
main() {
	deque<l> q;
	l N;cin >> N;
	l M = N - 1;
	L V,A(N, 0),a(N, -1),D(N, 1),J(N, 0),n(N, 1);
	vector<L> T(N);
	r(i, N * 2) {
		L w;
		w.B(i);
		r(j, 62)
			w.B((w[j] * w[j]) % m);
		p.B(w);
	}
	r(i, M) {
		l X, Y;
		cin >> X >> Y;
		X--; Y--;
		T[X].B(Y);
		T[Y].B(X);
		A[X]++;
		A[Y]++;
	}
	q.B(0);
	J[0] = 1;
	V.B(0);
	while (!q.empty()) {
		l x = q.front();
		q.pop_front();
		r(i, A[x]) {
			l E = T[x][i];
			if (!J[E]) {
				J[E] = 1;
				q.B(E);
				a[E] = x;
				V.B(E);
			}
		}
	}
	r(j, N) {
		l i = N - 1 - j,x = V[i];
		r(j, A[x]) {
			l E = T[x][j];
			if (E == a[x])
				continue;
			D[x] += D[E];
		}
	}
	r(i, N)
		n[0] = ((n[0]*(i + 1) % m)*P(D[i], m - 2))% m;
	r(j, N - 1) {
		l x = V[j + 1];
		n[x] = (((n[a[x]] * D[x]) % m) * P(N - D[x], m - 2)) % m;
	}
	r(i, N)
		cout << n[i] << "\n";
}

Measured memory_bytes: 236840
from sys import stdin
H, W = [int(_) for _ in stdin.readline().rstrip().split()]
C = [list(map(int, stdin.readline().rstrip().split())) for _ in range(10)]
A = [list(map(int, stdin.readline().rstrip().split())) for _ in range(H)]
D = [0]*10

def warshall_floyd():
    for k in range(10):
        for i in range(10):
            for j in range(10):
                C[i][j] = min(C[i][j], C[i][k] + C[k][j])

warshall_floyd()
for i in range(10):
    D[i] = C[i][1]
ans = 0
for i in range(H):
    for j in range(W):
        if A[i][j] >= 0:
            ans += D[A[i][j]]
print(ans)

Measured memory_bytes: 40284
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c[5]={0,0,0,0,0};
	cin>>a>>b;
	c[a]++;c[b]++;
	for(int i=1;i<=3;i++){
		if(c[i]==0){
			cout<<i<<endl;
			break;
		}
	}
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  
  int a = n / 1000;
  int b = (n - a * 1000) / 100;
  int c = (n - a * 1000 - b * 100) / 10;
  int d = (n - a * 1000 - b * 100 - c * 10);
  
  if ((a == b && b == c) || (b == c && c == d))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define int long long   // aaaaaaaaaaaaaaaaaa
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define SIZE(buff) (sizeof(buff)/sizeof(buff[0]))
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
template<typename T, typename U>ostream& operator << (ostream& os, pair<T, U>& pair_var)
{os << "(" << pair_var.first << ", " << pair_var.second << ")";return os;}
// head
int t,q,m,n,k,res,tmp,tmp2;
int a[22][22] = {};
int b[200010] = {};
VVI g(100010);
queue<int> que2;
int dp[10000000]={};
string s;

signed main() {
	cin.tie(0);
    ios::sync_with_stdio(false);
	std::cin >>n;
	VVI vec(n);
	rep(i,0,n){
		rep(j,0,n){
			cin>>a[i][j];
			if (a[i][j]){
				vec[i].pb(j);
			}
		}
	}
	dp[0] = 1;
	rep(j,0,n){
		per(i,0,1<<(n+1)){
			if (dp[i]){
				for(int k : vec[j]){
					if (i & (1<<k)){
						continue;
					}
					dp[i|1<<k] += dp[i];
					dp[i|1<<k] %= mod;
				}
			}
		}
    }
	cout<<dp[(1<<n)-1]%mod<<endl;
}

Measured memory_bytes: 21120
package main

import (
	"fmt"
)

func main() {

	var S, T, U string
	fmt.Scanf("%s %s", &S, &T)

	var A, B int
	fmt.Scanf("%d %d", &A, &B)
	fmt.Scanf("%s", &U)

	if S == U {
		fmt.Println(A-1, B)
	} else {
		fmt.Println(A, B-1)
	}

}


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

struct edge{int from, to; lint cost;};

const int MAX_N = 1000, MAX_M = 2000;
int N, M;
edge E[MAX_M+5];
lint INF = 1e15, d[MAX_N+5];

bool bellman_ford(int s){
    for(int i=0;i<MAX_N+5;i++) d[i] = INF;
    d[s] = 0;

    for(int i=0;i<2*N;i++){
        bool update = false;
        for(int j=0;j<M;j++){
            edge e = E[j];
            if(d[e.from] != INF && d[e.from]+e.cost < d[e.to]){
                d[e.to] = d[e.from] + e.cost;
                if(e.to==N) update = true;
            }
        }

        if(i>=N-1 && update) return true;
    }
    return false;
}

int main(){
    cin >> N >> M;
    for(int i=0;i<M;i++) cin >> E[i].from >> E[i].to >> E[i].cost;
    for(int i=0;i<M;i++) E[i].cost *= (-1);

    if(bellman_ford(1)) cout << "inf" << endl;
    else cout << d[N] * (-1) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 3e5 + 100;

int main() {
	ios::sync_with_stdio(0);
	int n,f=0;
	cin >> n;
	for (int i = 1,x; i <= n; i++) {
		cin >> x;
		if (x % 2 == 0) {
			if (x % 3 != 0 && x % 5 != 0)
				f = 1;
		}
	}
	if (f == 1)
		cout << "DENIED";
	else
		cout << "APPROVED";
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
    int N, K, ans; cin >> N >> K;
  	ans = 0;
    for (int i = 0; i < N; i++)
    {
        int hi; cin >> hi;
        if ( hi >= K ) { ans++; }
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define rep(i,n) for(int i=0;i<n;i++)
int gcd(int a, int b){
    int r=1;
    while(r!=0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
void revStr(char* str){
    int size = strlen(str);
    int i,j;
    char tmp = {0};
    for(i = 0, j = size - 1; i < size / 2; i++, j--){
        tmp = str[i];
        str[i] = str[j];
        str[j] = tmp;
    }return;
}
typedef struct{
    int a,b;
}data;

//昇順
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}
//構造体降順
int comp( const void *c1, const void *c2 )
{
  data test1 = *(data *)c1;
  data test2 = *(data *)c2;
  int tmp1 = test1.b;   /* b を基準とする */
  int tmp2 = test2.b;
  return tmp2 - tmp1;
}


int kai(int n){
    if(n==0){
        return 1;
    }
    int sum=1;
    for(int i=1;i<=n;i++){
        sum*=i;
    }
    return sum;
}

int main(){
    int A,B,C,X;
    scanf("%d%d%d%d",&A,&B,&C,&X);
    int cnt=0;
    rep(i,A+1){
        rep(j,B+1){
            rep(k,C+1){
                if(500*i+100*j+50*k==X){
                    cnt++;
                }
            }
        }
    }
    printf("%d",cnt);
}



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

typedef long long ll;
const int maxn = 1e5 + 3;

std::queue<ll> q;
std::vector<ll> res;

int main() {
    for(int i = 1; i <= 9; ++i)
        q.push(i);
    while(!q.empty() && res.size() < maxn) {
        auto u = q.front();
        q.pop();
        res.push_back(u);
        for(int i = std::max(0ll, u % 10 - 1); i <= std::min(9ll, u % 10 + 1); ++i) {
            q.push(u * 10ll + i);
        }
    }
    // printf("%zu\n", q.size());
    // printf("%lld\n", res.back());
    // for(int i = 0; i + 1 < maxn; ++i)
    //     assert(res[i] < res[i + 1]);
    int n;
    scanf("%d", &n);
    printf("%lld\n", res[n - 1]);
    return 0;
}

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

ll ab(ll x){
	if(x < 0) x *= -1;
	return x;
}

int main(){
	ll k; cin >> k;
	vl lun(9); rep(i,9)lun[i] = i+1;
	ll r = 0;// 桁
	while(lun.size() <= k){
		ll s = lun.size();
		for(ll i = r;i < s;i++){
			rep(j,10){
				if(ab(j-(lun[i]%10)) <= 1)lun.push_back(lun[i]*10+j);
			}
		}
		r = s;
	}
	cout << lun[k-1] << endl;
}

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

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

using namespace std;

typedef long long LL;

const LL INF = 1LL << 60;

template<typename T> inline
ostream& operator << (ostream& os, const vector<T>& vec) {
    os << "[ ";
    REP(i, vec.size()) {
        os << vec[i] << " ";
    }
    os << "]";

    return os;
}

int dfs(int n, const vector<int> &hs) {
    if (n == hs.size() - 1) {
        return 0;
    }

    int cost1 = n + 1 < hs.size() ? abs(hs[n] - hs[n + 1]) + dfs(n + 1, hs) : int(1e5);
    int cost2 = n + 2 < hs.size() ? abs(hs[n] - hs[n + 2]) + dfs(n + 2, hs) : int(1e5);

    int ret = min(cost1, cost2);

    return ret;
}

int dfs_memo(int n, const vector<int> &hs, vector<LL> &memo) {
    if (memo[n] < INF) {
        return memo[n];
    }

    if (n == hs.size() - 1) {
        return 0;
    }

    LL cost1 = n + 1 < hs.size() ? abs(hs[n] - hs[n + 1]) + dfs_memo(n + 1, hs, memo) : INF;
    LL cost2 = n + 2 < hs.size() ? abs(hs[n] - hs[n + 2]) + dfs_memo(n + 2, hs, memo) : INF;

    int ret = min(cost1, cost2);

    memo[n] = ret;

    return ret;
}

template <typename T> inline
void chmin(T &a, T b){
    if (a > b) {
        a = b;
    }
}

int dp1(const vector<int> &hs) {
    vector<int> costs(hs.size());

    costs[0] = 0;
    costs[1] = abs(hs[0] - hs[1]);

    FOR(i, 2, hs.size()) {
        costs[i] = min(costs[i - 2] + abs(hs[i - 2] - hs[i]), costs[i - 1] + abs(hs[i - 1] - hs[i]));
    }

    return costs.back();
}

int dp2(const vector<int> &hs) {
    vector<LL> costs(hs.size(), 1LL << 60);

    costs[0] = 0;
    REP(i, costs.size()) {
        if (i + 1 < costs.size()) chmin(costs[i+1], costs[i] + abs(hs[i] - hs[i + 1]));
        if (i + 2 < costs.size()) chmin(costs[i+2], costs[i] + abs(hs[i] - hs[i + 2]));
    }

    return costs.back();
}

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

    int N; cin >> N;

    vector<int> h(N);
    REP(i, N) cin >> h[i];

//    cout << dfs(0, h) << endl;

    vector<LL> memo(N, INF);
    cout << dfs_memo(0, h, memo) << endl;

//  cout << dp1(h) << endl;

//    cout << dp2(h) << endl;
}


Measured memory_bytes: 6144
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

int main(){
    int n; cin >> n;
    cout << n*n*n << endl; return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define poly vector<ll>
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
inline char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x=0;char ch=gc();bool positive=1;
	for(;!isdigit(ch);ch=gc()) if(ch=='-') positive=0;
	for(;isdigit(ch);ch=gc()) x=x*10+ch-'0';
	return positive?x:-x;
}
inline void write(ll x){
	if(x<0){
		x=-x;putchar('-');
	}
	if(x>=10) write(x/10);
	putchar('0'+x%10);
}
inline void writeln(ll x){write(x);puts("");}
inline void writep(ll x){write(x);putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=1e5+5;
int head[N],opt;
ll a[N];
poly v[N];
bool d=1;
void dfs(int u,int fa){
	ll sum=0,mx=0;int t=0;
	for(auto k:v[u]){
		if(k==fa) continue;
		dfs(k,u);t++;
		sum+=a[k];mx=max(mx,a[k]);
	}
	if(t==0) return;
	ll x=sum-a[u],y=2*a[u]-sum;
	if(x<0||y<0||x>min(sum-mx,sum/2)||(fa==0&&y)) d=0;
	a[u]=y;
}
int main(){
	int n=read();
	For(i,1,n) a[i]=read();
	For(i,1,n-1){
		int x=read(),y=read();
		v[x].pb(y);v[y].pb(x);
	}
	int rt=0;
	For(i,1,n) if(v[i].size()>1) rt=i;
	if(rt) dfs(rt,0);
	else d=(a[1]==a[2]);
	if(d) puts("YES");
	else puts("NO");
}

Measured memory_bytes: 18408
#include <iostream>
#include <string>
#include <sstream>
#include <vector>

using namespace std;

long count(int l, int k, vector<long> &memo){
  if(l < k){
    if(l < 1){
      return 0;
    }else{
      if(memo[l-1] != -1) return memo[l-1];
      long c = 1 + count(l - 2, k, memo);
      memo[l-1] = c;
      return c;
    }
  }else{
    if(memo[l-1] != -1) return memo[l-1];
    long c = 2 + count(l - (k+1), k, memo) + count(l - 2, k, memo);
    memo[l-1] = c;
    return c;
  }
}
  
int main(int argc, char *argv[])
{
  string line;
  while(getline(cin, line)){
    int l, k;
    istringstream iss(line);
    iss >> l >> k;
    vector<long> memo(l, -1);
    long pattern = count(l, k, memo);
    cout << pattern << endl;
  }
}

Measured memory_bytes: 3224
#include<iostream>
#include<vector>
#include<stack>
#define F(i,n) for(int i=0;i<n;i++)
#define lli long long int
#define vi vector<int>
#define vll vector<long long>
#define pb(x) .push_back(x)
using namespace std;
void printVector(vector<int> v)
{
    char ch = ' ';
    for(int i=0;i<v.size();i++)
    {
        printf("%d",v[i]);
        printf("%c",ch);
    }

}


int main(){
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    int n; cin>>n;
    vector<lli> v;
    F(i,n)
    {
        lli x; cin>>x;
        v pb(x);
    }
    stack<lli> s;
    vector<lli> diff;
    F(i,n)
    {
        if(i==0)
        s.push(v[i]);
        else
        {
            if(v[i]<s.top())
            {
                diff pb(s.top() - v[i]);
            }
            else
            {
                s.push(v[i]);
            }
            
        }
    }
    lli sum=0;
    F(i,diff.size())
    {
        sum+=diff[i];
    }
    cout<<sum;
 return 0;
}

Measured memory_bytes: 7520