akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
typedef long long ll;
struct edge { ll s, t, x; };
typedef pair<ll, ll> P;
typedef pair<double, P> event;
const ll MAX = 510000;
const ll MOD = 1000000007;
#define INF (ll)10000000000000000

int main() {
  int X;
  cin>>X;
  if(X<=599){cout<<8;return 0;}
  if(X<=799){cout<<7;return 0;}
  if(X<=999){cout<<6;return 0;}
  if(X<=1199){cout<<5;return 0;}
  if(X<=1399){cout<<4;return 0;}
  if(X<=1599){cout<<3;return 0;}
  if(X<=1799){cout<<2;return 0;}
  if(X<=1999){cout<<1;return 0;}
}


Measured memory_bytes: 3636
import itertools

n = int(input())

a = list(input().split())
b = list(input().split())
str_a = ''.join(a)
str_b = ''.join(b)
li = [x for x in range(1, n+1)]
map = map(str, li)

p = itertools.permutations(map)
sorted_list = []
for v in p:
    tmp = ''.join(v)
    sorted_list.append(tmp)
sorted_list.sort()

ai = 0
bi = 0
for v in range(len(sorted_list)):
    if str_a == sorted_list[v]:
        ai = v
    elif str_b == sorted_list[v]:
        bi = v
res = abs(ai-bi)
if a == b: res = 0
print(res)

Measured memory_bytes: 11704
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using namespace std;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
const int MX = 1000000000;
 
int main(){
  int N;
  cin >> N;
  vector<int> len(N);
  rep(i,N)cin >> len[i];
  sort(len.begin(), len.end());
  int ans = 0;
  
  rep(j,N){
    rep(k,j){
      rep(l,k){
        if(len[l] != len[k] && len[k] != len[j] && len[l] + len[k] > len[j]){
          ans++;
        }
      }
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3604
c = []
for i in ["S","H","C","D"]:
    for j in range(1,14):
        c.append("{} {}".format(i,j))
n = int(input())
a = [] 
for i in range(n):
    a.append(input())
d = [i for i in c if i not in a]
if len(d) != 0:
    print(*d,sep="\n")


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

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1; 
   // cin >> t;
    for(int T = 0; T < t ; T++){
        ll a, b, c;
        cin >> a >> b >> c;
        if(b*c >= a)
            cout << "Yes" << endl;
        else
            cout << "No" << endl; 
    }
    return 0;
}

Measured memory_bytes: 3568
import java.util.*;

public class Main{
  public static void main(String[] args) {
   Scanner sc = new Scanner(System.in);
   int a = sc.nextInt();
   int b = sc.nextInt();
   if(a + b == 15){
     System.out.println("+");
   }else if(a * b == 15){
     System.out.println("*");
   }else{
     System.out.println("x");
   }
 }
}


Measured memory_bytes: 23124
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		try {
			int a = sc.nextInt();
			int b = sc.nextInt();

			if (a + b >= 24) {
				System.out.println(a + b - 24);
			} else {
				System.out.println(a + b);
			}

		} finally {
			sc.close();
		}
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define all(a) a.begin(),a.end()
#define allr(a) a.rbegin(),a.rend()
#define ff first
#define sc second
#define INF 3000000000
#define SINF 2*(1e18)
#define inf -10000000
#define pb push_back
#define forr(i,p,n) for(int i=p;i<n;i++)
#define mpk make_pair
#define upb(a,s) upper_bound(a.begin(),a.end(),s)
#define lwb(a,s) lower_bound(a.begin(),a.end(),s)
#define mem(a,val) memset(a,val,sizeof a)
#define cc continue
#define eb emplace_back
#define bb break
#define mostbit(n) 32-__builtin_clz(n)-1
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
//typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> order_set;
ll dp[110][100010];
ll v[100010],pes[100010];
ll n;
ll solve(ll pos,ll aux){
  if(aux==0)return 0;
  if(pos==n)return 0;
  ll &ans=dp[pos][aux];
  if(dp[pos][aux]!=-1)return dp[pos][aux];
  if(pes[pos]>aux)return ans=solve(pos+1,aux);
  return ans=max(solve(pos+1,aux),v[pos]+solve(pos+1,aux-pes[pos]));
}
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie();
    ll a,b,c,d,t,m,k;
    cin>>n>>k;
    forr(i,0,n){
      cin>>pes[i]>>v[i];
    }
    mem(dp,-1);
    cout<<solve(0,k)<<endl;
    
}


Measured memory_bytes: 89612
#include <bits/stdc++.h>
#define for0(i,b) for(int i=0 ; i< b ;i++)
#define for1(i,b) for(int i=1 ; i<=b ;i++)
#define reps(i,a,b) for(int i=a ; i< b.length() ;i++)
typedef long long ll;
#define MOD 1000000007

using namespace std;




int main()
{
  int m,n,a, sum=0 ;
  cin >> m >> n ;

  for0(i,n){
    cin >> a ;
    sum += a ;
    if(sum > m){
    cout <<-1;
    return 0;
    }
  }
cout<< m-sum;

}


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

int main() {

    ll A, B;
    cin >> A >> B;

    ll tmp = (A+B)/2;
    //cout << abs(tmp -A) << ", " << abs(tmp-B) << endl;
    if (abs(tmp - A) == abs(tmp - B)) {
        cout << tmp << endl;
    }
    else {
        cout << "IMPOSSIBLE" << endl;
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  rep(i,n-2) {
    if(s[i] == 'A') {
      if(s[i+1] == 'B'&& s[i+2] == 'C') ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
int main(){
	ll a,b,n;
	cin >> a >> b >> n;
	cout << (a * min(n,b-1)) / b - a * (min(n,b-1) / b) << endl;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

template <typename T>
inline void read(T &x)
{
    T data = 0, f = 1;
    char ch = getchar();
    while (!isdigit(ch))
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (isdigit(ch))
    {
        data = (data << 3) + (data << 1) + ch - '0';
        ch = getchar();
    }
    x = f * data;
}
template <typename T, typename... Args>
inline void read(T &t, Args &... args)
{
    read(t);
    read(args...);
}
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
const int maxn = 1e5 + 9;

signed main()
{
    //freopen("in.txt","r",stdin);
    //freopen("data.txt","w",stdout);
    //std::ios::sync_with_stdio(false);
    //std::cin.tie(0);
    //std::cout.tie(0);
    int a;
    cin >> a;
    cout << (a ? 0 : 1) << endl;
    //fclose(stdin);
    //fclose(stdout);
    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define ll  long long
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define per(i,a,b)  for(ll i=b-1;i>=a;i--)
#define pb push_back
#define Max(x,y,z) max(x,max(y,z))
#define f first
#define s second
#define lbd lower_bound
#define sz(x)       (ll)x.size()
#define pi 3.1415926536
#define mod 1000000007
#define MOD 998244353
using namespace std;
/*bool isprime(ll x)
{
    for(ll i=2;(i*i)<=x;i++)
    {
        if(x%i==0) return 0;
    }
    return 1;
}
ll power(ll x,ll n)
{
    ll res=1;
    while(n>0){
    if(n%2) res=(res*x)%mod;
    x=(x*x)%mod;
    n=n/2;}
    return res;
}*/
void solve()
{
            ll n,m,k,l=0,r=0,z,sum1=0,h,res=0,a,b,c,d,x=0,y=0;
            cin>>n;
            ll ar[n];
            double ans;
            rep(i,0,n){
            cin>>ar[i];ans+=(double) 1/ar[i];}
            cout<<1/ans<<setprecision(12);


            }

        int main()
        {
            speed_up
            ll t=1;
            //cin>>t;
            while(t--)
                solve();
        }


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define li long long int
#define pb push_back
using namespace std;
int main(){
double w , h, x , y;
 cin>>w>>h>>x>>y;
 double ans ;
 int p;
cout<<setprecision(15)<<fixed;
if(x==w/2&&y==h/2){
    p = 1;
}
else
    p =0;
 ans = (w*h)/2;
 cout<<ans<<" "<<p<<endl;




}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
 using namespace std; 
 int main() { 
   int i ;
   string S;
   for(int i=0;i<3;i++) {
   cin>> S[i];
   }
   string Ans="Yes";
   
   if(S[0]=='A' && S[1]=='A' && S[2]=='A') Ans="No";
   if(S[0]=='B' && S[1]=='B' && S[2]=='B') Ans="No";
   
   cout<<Ans<<endl;
   return 0; 
 }


Measured memory_bytes: 256
require 'pp'

# 入力値を数値で返却する
def gets_i()
  gets.chomp.to_i
end

X = gets_i

i = 0
total = 100
while true do
  if total >= X
    puts i
    exit
  end
  i += 1
  total = (total * 1.01).floor
end


Measured memory_bytes: 14568
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < n; ++i)

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n) cin >> c[i];
    sort(a.begin(), a.end());
    sort(c.begin(), c.end());

    // b[i]より小さい要素がaに何個あるか
    int aa = 0;
    // b[i]より大きい要素がcに何個あるか
    int cc = 0;
    long long ans = 0;
    rep(i,n) {
        aa = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
        cc = c.end() - upper_bound(c.begin(), c.end(), b[i]);
        ans += (long long)aa * cc;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
a,b,q = map(int,input().split())
s = sorted([int(input()) for i in range(a)])
t = sorted([int(input()) for i in range(b)])

from bisect import bisect

for i in range(q):
    x = int(input())

    s_i = bisect(s,x)
    d1 = d2 = 10**11
    if s_i<a:
        d1 = s[s_i]-x
        t_i = bisect(t,s[s_i])
        buf = 10**11
        if t_i<b:
            buf = t[t_i]-s[s_i]
        if t_i>0:
            buf = min(buf,s[s_i]-t[t_i-1])
        d1 += buf
    if s_i>0:
        d2 = x-s[s_i-1]
        t_i = bisect(t,s[s_i-1])
        buf = 10**11
        if t_i<b:
            buf = t[t_i]-s[s_i-1]
        if t_i>0:
            buf = min(buf,s[s_i-1]-t[t_i-1])
        d2 += buf
    
    t_i = bisect(t,x)
    d3 = d4 = 10**11
    if t_i<b:
        d3 = t[t_i]-x
        s_i = bisect(s,t[t_i])
        buf = 10**11
        if s_i<a:
            buf = s[s_i]-t[t_i]
        if s_i>0:
            buf = min(buf,t[t_i]-s[s_i-1])
        d3 += buf
    if t_i>0:
        d4 = x-t[t_i-1]
        s_i = bisect(s,t[t_i-1])
        buf = 10**11
        if s_i<a:
            buf = s[s_i]-t[t_i-1]
        if s_i>0:
            buf = min(buf,t[t_i-1]-s[s_i-1])
        d4 += buf

    print(min(d1,d2,d3,d4))

Measured memory_bytes: 12848
from collections import Counter
n = int(input())
sList = [input() for _ in range(n)]
c = Counter(sList).most_common()
ans = []
for i in range(len(c)):
    if c[i][1] == c[0][1]:
        ans.append(c[i][0])
    else:
        break
ans.sort()
print("\n".join(ans))


Measured memory_bytes: 45040
#include <bits/stdc++.h>
#define int long long int
#define endl "\n"
#define loop(i,n) for(int i=0;i<n;i++)
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fileread freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define pb push_back
#define mp make_pair
#define itr iterator
#define fi first
#define se second
#define pii pair<int,int>
#define pci pair<char,int>
#define u_map unordered_map
#define u_set unordered_set
#define u_mmap unordered_multimap
#define u_mset unordered_multiset
# define pi 3.14159265358979323846
using namespace std;

/*
vector< vector <int> > adj;

void addedge(int u, int v){
    adj[u].pb(v);
    adj[v].pb(u);
}


for(int i=0;i<n;i++){
    cout<<"i is : "<<i<<endl;
    for(int j=0;j<adj[i].size();j++) cout<<adj[i][j]<<" ";
    cout<<endl<<endl;
}
*/

int row,col;
bool vis[52][52];
int lev[52][52];
char adj[52][52];

bool bfs(){
    for(int i=1;i<=row;i++){
        for(int j=1;j<=col;j++) lev[i][j]=1;
    }
    memset(vis,false,sizeof(vis));
    queue< pii > q;
    q.push(mp(1,1));
    vis[1][1]=true;
    while(!q.empty()){
        pii pp=q.front();
        q.pop();
        int prow=pp.fi,pcol=pp.se;
        //cout<<prow<<" "<<pcol<<endl;
        for(int i=-1;i<=1;i++){
            for(int j=-1;j<=1;j++){
                int crow=prow+i,ccol=pcol+j;
                if(i*j==0){
                    if((prow+i>=1 && prow+i<=row) && (pcol+j>=1 && pcol+j<=col)){
                        if(!vis[crow][ccol] && adj[crow][ccol]=='.'){
                            vis[crow][ccol]=true;
                            q.push(mp(crow,ccol));
                            lev[crow][ccol]=lev[prow][pcol] + 1;
                            if(crow==row && ccol==col) return true;
                        }
                    }
                }
            }
        }
    }
    return false;
}


signed main() {
	/*
	----------
	----------
	----------
	----------
	----------
	----------
	----------
	----------
	----------
	----------
	----------
	----------
	----------
	----------
	*/
    cin>>row>>col;
    int wh=0,bl=0;
    for(int i=1;i<=row;i++){
        for(int j=1;j<=col;j++){
            cin>>adj[i][j];
            if(adj[i][j]=='.') wh++;
            else bl++;
        }
    }
    
/*    
    for(int i=1;i<=row;i++){
        for(int j=1;j<=col;j++){
            cout<<lev[i][j]<<" ";
        }
        cout<<endl;
    }
  */  
    if(adj[1][1]=='#' || adj[row][col]=='#') cout<<-1;
    else{
        if(!bfs()){
            cout<<-1;
        }
        else{
            int num=lev[row][col];
            cout<<wh-num;
        }
    }

}















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

typedef long long ll;

/*
const ll M = 1000000007;
vector<ll> fac(3001);
vector<ll> ifac(3001);
ll mpow(ll x, ll n){
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}
 
ll comb(ll a, ll b){
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0 || b < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}
*/


ll lcm(ll a,ll b){
 
  ll r, x, tmp;
  x = a * b;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return x/b;
}

ll gcd(ll a ,ll b){
    if(a==0){return b;}
    else if(b==0){return a;}
    else{
    ll tmp,r;
    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
    }
    
    r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
    }
}

bool sosu(ll p){
    bool ans = true;
    double psqrtd = pow(p, 0.5);
    ll psqrt = psqrtd;
    for(ll i = 2; i <= psqrt; i++){
        if(p%i==0)ans = false;
    }
    if(p==1)ans = false;
    return ans;
}



int main(void){
    ll n;
    cin >> n;
    vector<pair<ll,ll>> s(n);
    for(ll i=0;i<n;i++){
        ll x;
        cin >> x;
        s[i] = make_pair(x,i);
    }
    sort(s.begin(),s.end());
    cout << s[0].second+1;
    for(ll i=1;i<n;i++){
        cout << ' ' << s[i].second+1;
    }
    cout << endl;
    return 0;
}


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

#define MAX 200005

int main()
{
	vector<char> S(MAX);
	vector<char> T(MAX);
	int count1 = 0;
	int count2 = 0;
	
	for (int i = 0; i < MAX; i++) {
		S[i] = getchar();
		count1++;
		if (S[i] == '\n')
			break;
	}
	for (int i = 0; i < count1; i++) {
		T[i] = getchar();
		if (S[i] != T[i])
			count2++;
	}
	cout << count2 << endl;

	return 0;
}

Measured memory_bytes: 3744
import java.util.*;

public class Main { //クラス名はMain
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
      	int n=sc.nextInt();
      	ArrayList<ArrayList<Integer>> x=new ArrayList<>();
      	ArrayList<ArrayList<Integer>> y=new ArrayList<>();
      	for (int i=0;i<n;i++){
      		x.add(new ArrayList<Integer>());
          	y.add(new ArrayList<Integer>());
          	int size=sc.nextInt();
          	for(int j=0;j<size;j++){
            	x.get(i).add(sc.nextInt());
              	y.get(i).add(sc.nextInt());
            }
        }
      	long o=0;
      	int pow=(int)Math.pow(2,n)-1;
      	for(int i=pow;i>=0;i--){
          	boolean judge=true;          	
          	String bin = Integer.toBinaryString(i);
          	int l=bin.length();
          	int r[]=new int[n];
          	int count_one=0;	//正直者の数を数える
          	for(int j=0;j<l;j++){
             //System.out.println(bin);		
              count_one+=(int)bin.charAt(j)-48;
              r[l-1-j]=(int)bin.charAt(j)-48;
              
            }
          	for(int j=0;j<n;j++){
            	if(r[j]==1){
                  	int size=x.get(j).size();
                  	for(int k=0;k<size;k++) {  
                      	//System.out.println(bin+" "+x.get(j).get(k)+" "+y.get(j).get(k)+" "+r[x.get(j).get(k)]);
                        if(y.get(j).get(k)==r[x.get(j).get(k)-1]){
                          continue;
                        }else {
                          judge=false;
                          break;
                        }
                    }
                }
              	if(!judge)break;
            }
          if(judge&&count_one>o){
           																												
            o=count_one;
          }
        }      	
     	 System.out.println(o);
    }
}

Measured memory_bytes: 30360
using System;
using System.Collections.Generic;

namespace ABC070_D___Transit_Tree_Path
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var nodes = new Node[N + 1];
            for (int i = 1; i < N + 1; i++) nodes[i] = new Node();
            for (int i = 0; i < N - 1; i++)
            {
                var readEdge = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
                nodes[readEdge[0]].connection.Add(readEdge[1]);
                nodes[readEdge[0]].distance.Add(readEdge[2]);
                nodes[readEdge[1]].connection.Add(readEdge[0]);
                nodes[readEdge[1]].distance.Add(readEdge[2]);
            }

            var QK = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            nodes[QK[1]].fromK = 0;
            var checkNodes = new Queue<Node>();
            checkNodes.Enqueue(nodes[QK[1]]);

            while (checkNodes.Count != 0)
            {
                var currentNode = checkNodes.Dequeue();
                for (int i = 0; i < currentNode.connection.Count; i++)
                {
                    var nextNode = nodes[currentNode.connection[i]];
                    if (nextNode.fromK != -1) continue;
                    checkNodes.Enqueue(nextNode);
                    nextNode.fromK = currentNode.fromK + currentNode.distance[i];
                }
            }

            for (int i = 0; i < QK[0];i++)
            {
                var xy = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
                Console.WriteLine(nodes[xy[0]].fromK + nodes[xy[1]].fromK);
            }
        }
    }

    class Node
    {
        public List<int> connection;
        public List<long> distance;
        public long fromK;
        public Node()
        {
            connection = new List<int>();
            distance = new List<long>();
            fromK = -1;
        }
    }
}


Measured memory_bytes: 47116
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
#define N 1000
#define N2 N*N
int dx[4]={1,0,-1,0};
int dy[4]={0,-1,0,1};
bool prime[N2+1];
int cave[N][N]={};
pair<int,int> dp[N][N];
int m,n;

pair<int,int> rec(int x,int y){
    if(y<0 || x<0 || x==N || cave[x][y]>m)return pair<int,int>(0,0);
    if(dp[x][y].first)return dp[x][y];
    pair<int,int> child[3];
    child[0]=rec(x-1,y-1);
    child[1]=rec(x,y-1);
    child[2]=rec(x+1,y-1);
    sort(child,child+3);
    if(child[2].first==0 && prime[cave[x][y]])return dp[x][y]=pair<int,int>(1,cave[x][y]);
    if(prime[cave[x][y]])child[2].first++;
    return dp[x][y]=child[2];
}

int main(void){
    fill(prime,prime+N2+1,true);
    prime[0]=prime[1]=false;
    for(int i=2;i<=N2;i++){
        if(!prime[i])continue;
        for(int k=2;i*k<=N2;k++)prime[i*k]=false;
    }

    int x=0,y=N-1,d=0;
    pair<int,int> locate[N2+1];
    for(int i=N2;i>0;i--){
        cave[x][y]=i;
        locate[i] = pair<int,int>(x,y);
        int nextX=x+dx[d],nextY=y+dy[d];
        if(nextX<0 || nextX==N || nextY<0 || nextY==N || cave[nextX][nextY])d=(d+1)%4;
        x+=dx[d];
        y+=dy[d];
    }


    while(cin>>m>>n, m|n){
        rep(i,N)rep(j,N)dp[i][j].first=dp[i][j].second=0;
        pair<int,int> tmp=rec(locate[n].first,locate[n].second);
        cout<<tmp.first<<" "<<tmp.second<<endl;
    }

    return 0;
}

Measured memory_bytes: 21748
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
typedef long long ll;
const ll inf = 1e9;
int main(){
    int q; cin >> q;
    multiset<ll> st;
    rep(i,q){
        ll com, x, y;
        cin >> com >> x;
        if(com == 0){
            st.insert(x);
            cout << st.size() << endl;
        }else if(com == 1)cout << st.count(x) << endl;
        else if(com == 2)st.erase(x);
        else{
            cin >> y;
            for(multiset<ll>::iterator it=st.lower_bound(x); it != st.upper_bound(y); it++)cout << *it << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 12344
import sys

def main():
  N = int(input())
  P = sys.stdin.readline().rstrip().split()
  if '0' in P:
    print(0)
    return
  ans = 1
  for a in P:
    ans *= int(a)
    if ans > 1000000000000000000:
      print(-1)
      return
  print(ans)

if __name__ == "__main__":
    main()


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

using namespace std;

int const max_n = 1e5 + 5;
vector<int> gr[100005];
int visited[max_n];

int dfs(int x){
	int ans = 0;
	if(visited[x] != -1) return visited[x];
	for(auto i : gr[x]) {
		ans = max(ans, dfs(i)+1);
	}
	visited[x] = ans;
	return ans;
}

int main(){
	int n, m, u, v;
	cin>>n>>m;
	for(int x=0;x<m;x++){
		cin>>u>>v;
		gr[u].push_back(v);
	}
	for(int x=0;x<max_n;x++) visited[x] = -1;
	int ans =0;
	for(int x=1;x<=n;x++) ans = max(ans, dfs(x));
	cout<<ans;
	return 0;
}

Measured memory_bytes: 8192
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
A = LIST()
 
if all(x in A for x in [5,7]) and sum(A) == 17:
	print("YES")
else:
	print("NO")

Measured memory_bytes: 5452
#include<iostream>
#include<cmath>
#include<string>
#include<cstdlib>
#include<ctime>
#include<map>
#include<vector>
#include<list>
using namespace std;

#define ll long long
#define uint unsigned int
#define alloc(n,type) (type*)calloc(n,sizeof(type))
#define MODULE 1
#define RAND(min,max) (rand()%(max-min+1)+min)
#define repeat(i,condition) for(int i = 0; condition; i++)
#define LOG(log) cout<<#log<<" : "<<log<<'\n'
#define DEBUG() {cout<<"DEBUG "<<num_debug<<'\n'; num_debug++;}
int num_debug = 0;
bool* IsPrime;
vector<int> Prime;

int compare_int(const void* a, const void* b);
class Math {
public:
	template<typename T> static T Fac(int n) {
		T ans = 1;
		for (int i = 2; i <= n; i++) {
			ans *= i;
		}
		return ans;
	}
public :
	template<typename T> static T P(int n, int r) {
		T ans = 1;
		for (int i = 0; i < r; i++) {
			ans *= n - i;
		}
		return ans;
	}
public:
	template<typename T>static T C(int n, int r) {
		T nmr = 1;
		T dnm = 1;
		if (n - r < r)
			r = n - r;
		for (int i = 0; i < r; i++) {
			nmr *= n - i;
			dnm *= r - i;
		}
		return nmr / dnm;
	}
};
class Module_int {
public:
	static const int mod = MODULE;

public:
	static int add(int a, int b) {
		int ans = a + b;
		if (ans < 0)
			ans += mod;
		ans %= mod;
		return ans;
	}
public:
	static int mult(int a, int b) {
		return (a * b) % mod;
	}

public:
	static int Pow(int a, int b) {
		int base = a % mod;
		if (mod / 2 < abs(base))
			if (base < 0) {
				base += mod;  //negative
			}
			else {
				base -= mod;  //positive
			}

		return pow(base, b);
	}
};


int main(void) {
	srand((unsigned)time(NULL));

	int X;
	cin >> X;

	X -= 400;
	int a = X / 200;

	cout << 8 - a;

	return 0;
}


int compare_int(const void* a, const void* b) {
	return *(int*)a - *(int*)b;
}
void PrimeEnable(int n) {
	//initialize IsPrime
	IsPrime = (bool*)calloc(n + 1, sizeof(bool));
	for (int i = 0; i <= n; i++)
		IsPrime[i] = true;

	//IsPrime 
	IsPrime[0] = IsPrime[1] = false;
	for (int i = 2; i * i <= n; i++) {
		if (IsPrime[i])
			for (int j = i; i * j <= n; j++) {
				IsPrime[i * j] = false;
			}
	}

	//push back to Prime
	for (int i = 0; i <= n; i++) {
		if (IsPrime[i])
			Prime.push_back(i);
	}
}

//template name is "AtCoder_C++"

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

using namespace std;

int main() {
	
	long long n, a,b;
	cin >> n >> a >> b;

	long long min = (n - 1)*a + b;
	long long max = a + (n - 1)*b;
	
	cout << (max - min + 1 >0? max - min + 1 : 0) << endl;

	return 0;
}

Measured memory_bytes: 256
n=int(input())
if(n>=400 and n<=599):
  print("8")
elif(n>=600 and n<=799):
  print("7")
elif(n>=800 and n<=999):
  print("6")
elif(n>=1000 and n<=1199):
  print("5")
elif(n>=1200 and n<=1399):
  print("4")
elif(n>=1400 and n<=1599):
  print("3")
elif(n>=1600 and n<=1799):
  print("2")
elif(n>=1800 and n<=1999):
  print("1")

Measured memory_bytes: 9204
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
using namespace std;
int main(){
    int n;cin >> n;
    if(n%10==0){
        cout<<10<<endl;
    }else{
        string s =to_string(n);
      //  cout<<s<<endl;
        int count=0;
        for(int i=0;i<s.size();i++){
            count += s[i]-'0';
        }
        cout<<count<<endl;
    }
}

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

int main()
{
    bool s[14] ;
    bool h[14] ;
    bool c[14] ;
    bool d[14] ;
    for(ll i = 0 ; i < 14 ; i++)
    {
        s[i] = false ;
        h[i] = false ;
        c[i] = false ;
        d[i] = false ;
    }
    ll n ;
    cin >> n ;
    for(ll i = 0 ; i < n ; i++)
    {
        char A ;
        ll B ;
        cin >> A >> B ;
        if(A == 'S') s[B] = true ;
        else if(A == 'H') h[B] = true ;
        else if(A == 'C') c[B] = true ;
        else if(A == 'D') d[B] = true ;
    }
    ll remaining = 52 - n ;
    for(ll i = 1 ; i < 14 ; i++)
    {
        if(s[i] == false) cout << 'S' << " " << i << endl ;
    }
    for(ll i = 1 ; i < 14 ; i++)
    {
        if(h[i] == false) cout << 'H' << " " << i << endl ;
    }
    for(ll i = 1 ; i < 14 ; i++)
    {
        if(c[i] == false) cout << 'C' << " " << i << endl ;
    }
    for(ll i = 1 ; i < 14 ; i++)
    {
        if(d[i] == false) cout << 'D' << " " << i << endl ;
    }
}


Measured memory_bytes: 3100
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;

#define Yes() cout << "Yes" << endl;
#define No() cout << "No" << endl;

int N, M;
int L[200000], R[200000], D[200000];

vector<pair<int, int>> rel_pos[100001];
int pos[100001];
bool visited[100001];

int main(int argc, char* argv[]) {
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> L[i] >> R[i] >> D[i];
    rel_pos[L[i]].push_back(make_pair(R[i], D[i]));
    rel_pos[R[i]].push_back(make_pair(L[i], -D[i]));
  }

  for (int i = 1; i <= N; i++) {
    if (visited[i])
      continue;

    pos[i] = 0;
    visited[i] = true;

    queue<int> que;
    que.push(i);
    while (!que.empty()) {
      int vertex = que.front();
      que.pop();

      for (auto p : rel_pos[vertex]) {
        if (visited[p.first] && pos[p.first] != pos[vertex] + p.second) {
          cout << "No" << endl;
          return 0;
        }

        if (!visited[p.first]) {
          pos[p.first] = pos[vertex] + p.second;
          visited[p.first] = true;
          que.push(p.first);
        }
      }
    }
  }

  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 15072
#include <bits/stdc++.h>
#define in freopen("input.txt", "r" ,stdin)
#define out freopen("output.txt", "w" , stdout)
#define ll long long
#define inf 200005
#define fr first
#define  sc second
#define pb push_back
#define p_b pop_back
#define mp make_pair
using namespace std;
ll n,mw;
ll w[105];
ll v[105];
ll dp[105][100005];
int main (){
//in;out;
ios_base::sync_with_stdio(0);
cin >> n >> mw;
for (int i = 1; i <= n; i++) {
    cin >> w[i] >> v[i];
}

for (int i = 1; i <= n; i++){
    for (int j = 0; j <= mw; j++) {
         dp[i][j] = dp[i-1][j];
         if (j >= w[i] and dp[i][j] < dp[i-1][j-w[i]] + v[i]) {
             dp[i][j] = dp[i-1][j-w[i]] + v[i];
         }
    }
}

cout << dp[n][mw];
}


Measured memory_bytes: 79360
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

class Edge{
public:
    int to, cost, rev;
    Edge(int to0, int cost0, int rev0){
        to = to0;
        cost = cost0;
        rev = rev0;
    }
};

void dfs(int curr, int len, vector<vector<Edge> >& edges, vector<vector<bool> >& check, vector<int>& pass, int& ret1, vector<int>& ret2){
    bool ng = true;
    for(unsigned i=0; i<edges[curr].size(); ++i){
        if(!check[curr][i]){
            int to = edges[curr][i].to;
            int rev = edges[curr][i].rev;
            pass.push_back(to);
            check[curr][i] = true;
            check[to][rev] = true;
            dfs(to, len+edges[curr][i].cost, edges, check, pass, ret1, ret2);
            pass.pop_back();
            check[curr][i] = false;
            check[to][rev] = false;
            ng = false;
        }
    }

    if(ng && (len > ret1 || (len == ret1 && pass < ret2))){
        ret1 = len;
        ret2 = pass;
    }
}

int main()
{
    for(;;){
        int n, m;
        cin >> n >> m;
        if(n == 0)
            return 0;

        vector<vector<Edge> > edges(n);
        vector<vector<bool> > check(n);
        for(int i=0; i<m; ++i){
            int a, b, c;
            cin >> a >> b >> c;
            edges[a-1].push_back(Edge(b-1, c, edges[b-1].size()));
            edges[b-1].push_back(Edge(a-1, c, edges[a-1].size()-1));
            check[a-1].push_back(false);
            check[b-1].push_back(false);
        }

        vector<int> pass;
        int ret1 = 0;
        vector<int> ret2;
        for(int i=0; i<n; ++i){
            pass.push_back(i);
            dfs(i, 0, edges, check, pass, ret1, ret2);
            pass.pop_back();
        }

        cout << ret1 << endl;
        cout << (ret2[0] + 1);
        for(unsigned i=1; i<ret2.size(); ++i)
            cout << ' ' << (ret2[i] + 1);
        cout << endl;
    }
}

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

int main(){
	int b[3];
	for(int i = 0 ; i < 3 ; i ++){
		scanf("%d",&b[i]);
	}
	if(b[1] == b[0] && b[2] != b[0])cout << "Open" << endl;
	else cout << "Close" << endl;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
#define inf INFINITY
#define file freopen( "input.txt" , "r" , stdin) ; freopen( "output.txt" , "w" , stdout) ;
#define Gamed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define _3102_ main()
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;
const int N = 3e3 + 10;
const ll MX = 1e9;
const ll mod = 1e9 + 7;
const double eps = 1e-9 ;



int dp[N][N], step[N][N] ;  
string a , b ;

int solve( int i , int j ){
    if ( i == 0 || j == 0 ) return dp[i][j] = 0 ; 
    if ( dp[i][j] != -1 ) return dp[i][j] ; 
    if ( a[i] == b[j]){
        step[i][j] = 1 ; 
        return dp[i][j] = solve(i-1, j -1 ) + 1 ;
    }
    int l1 = solve( i -1 , j ) , l2 = solve ( i , j -1) ; 
    if ( l1 > l2){
        step[i][j] = 2 ; 
        return dp[i][j] = l1 ;
    }
    step[i][j] = 3 ; 
    return dp[i][j] = l2 ;
}

void show ( int i , int j ){
    if ( step[i][j] == 1){
        show(i-1, j -1 ) ; 
        cout << a[i] ; 
    }
    else if ( step[i][j] == 2){
        show  ( i - 1 , j ) ; 
    }
    else if ( step[i][j] == 3){
        show ( i , j-1) ; 
    }
}

int _3102_{
	Gamed
    cin >> a >> b ; 
    a.insert(0 , " "  ) , b.insert(0," ") ;
    memset ( dp , -1 , sizeof dp);
    solve( a.size()-1 , b.size() -1) ; 
    //cout << solve( a.size() -1 , b.size() - 1) << endl  ;
    //for  ( int i = 0 ; i < a.size() ; i ++){
    //    for ( int j = 0 ; j < b.size() ; j ++ ) 
    //        cout << dp[i][j]  << " " ;
    //        cout <<endl; 
    //} 
    show ( a.size() -1 , b.size() - 1) ; 
    return 0;
}



Measured memory_bytes: 74604
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define maxn 200005
using namespace std;

int N[10];


int main() {
    memset(N, -1, sizeof N);
    int n, m;
    cin >> n >> m;
    while(m--){
        int pos, x;
        cin >> pos >> x;
        if(N[pos] == -1){
            N[pos] = x;
        }
        else{
            if(N[pos] != x ){
                cout << -1 << endl;
                return 0;
            }
        }
    }
    if(n == 1){
        if(N[1] == -1) N[1] = 0;
        cout << N[1] << endl;
        return 0;
    }
    if(n == 2){
        if(N[1] != 0){
            if(N[1] == -1) N[1] = 1;
            if(N[2] == -1) N[2] = 0;
            cout << N[1]<<N[2] << endl;
        }
        else{
            cout << -1 << endl;
        }
        return 0;
    }
    if(n == 3){
        if(N[1] != 0){
            if(N[1] == -1) N[1] = 1;
            if(N[2] == -1) N[2] = 0;
            if(N[3] == -1) N[3] = 0;
            cout << N[1]<<N[2] << N[3] << endl;
        }
        else{
            cout << -1 << endl;
        }
        return 0;
    }



    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

#define BUF_SIZE 1000
#define ARR_SIZE 100

void print_array(int array[], int size)
{
  int i;
  for(i = 0; i < size; i++){
    if(i > 0) printf(" ");
    printf("%d", array[i]);
  }

  printf("\n");

  return ;
}

int bubble_sort(int array[], int size)
{
  int flag = 1;
  int tmp, j;
  int swap_size;
  int count = 0;

  while(flag){
    flag = 0;
    for(j = size - 1; 0 < j; j--){
      if(array[j] < array[j-1]){
        tmp = array[j];
        array[j] = array[j-1];
        array[j-1] = tmp;
        flag = 1;
        count++;
      }
    }
  }

  return count;
}

int main(void)
{
  char buf[BUF_SIZE];
  int array[ARR_SIZE];
  int size, i, swap_size;

  fgets(buf, BUF_SIZE, stdin);
  sscanf(buf, "%d", &size);

  for(i = 0; i < size; i++){
    scanf("%d", &array[i]);
  }

  swap_size = bubble_sort(array, size);

  print_array(array, size);
  printf("%d\n", swap_size);

  return 0;
}

Measured memory_bytes: 624
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class D
{
	public static void Main() => (new Solver()).Solve();
}

public class Solver
{
	public void Solve()
	{
		int K = GetInt();
		if(K <= 9)
		{
			WriteLine(K);
			return;
		}

		var list = new List<long>(){ 1, 2, 3, 4, 5, 6, 7, 8, 9 };
		var set = new HashSet<long>();
		foreach(var x in list)
			set.Add(x);
		
		while(true)
		{
			int count = list.Count;
			for(int i = 0; i < count; i++)
			{
				long x = list[i];
				long c = x % 10L;

				if(c > 0)
				{
					long tmp = 10L * x + c - 1L;
					if(!set.Contains(tmp))
					{
						list.Add(tmp);
						set.Add(tmp);
					}
				}

				{
					long tmp = 10L * x + c;
					if(!set.Contains(tmp))
					{
						list.Add(tmp);
						set.Add(tmp);
					}
				}
				
				if(c < 9)
				{
					long tmp = 10L * x + c + 1L;
					if(!set.Contains(tmp))
					{
						list.Add(tmp);
						set.Add(tmp);
					}
				}
			}
			if(set.Count >= K)
				break;
		}
		WriteLine(list[K - 1]);
	}
}

public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => Enumerable.Range(0, (int)N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(long N) => Enumerable.Range(0, (int)N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDouble()).ToArray();
	public static decimal[] GetDecimals(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDecimal()).ToArray();
	public static string[] GetStrings(long N) => Enumerable.Range(0, (int)N).Select(_ => GetString()).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) < 0)
			x = y;
	}

	public static void chmin<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) > 0)
			x = y;
	}

	public static void swap<T>(ref T x, ref T y)
	{
		T tmp = x;
		x = y;
		y = tmp;
	}
}

Measured memory_bytes: 29280
using namespace std;
typedef long long ll;
#include <string>
#include <vector>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>

#define out(S) cout<<(S)<<endl;
#define mod(i) ((i)%(ll)(1000000000 + 7))
ll modpow(ll i, ll j) { ll tmp = 1; while (j) { if (j % 2)tmp = mod(tmp*i); i = mod(i*i); j /= 2; }return tmp; }
#define divmod(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define For(i,a,b) for(size_t i=(a);i<(b);i++)
#define rFor(i,a,b) for(size_t i=(a)-1;i>=(b);i--)
#define Rep(i,a) for(size_t i=0;i<(a);i++)
#define rRep(i,a) for(size_t i=(a)-1;i>=0;i--)
#define pb(i) push_back(i);
#define Foreach(item,collection) for(auto item:collection)
using vi = vector<int>;


int main(){
	int a, b, c;
	cin >> a >> b >> c;
	int ans = min(a + b, a + c);
	ans = min(ans, c + b);
	out(ans);

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

const ll MAX = 1000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

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

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	string s;
	ll k;
	cin >> s >> k;
	
	ll d = s.size();

	ll a[d];
	zep(i, 0, d){
		a[i] = s[i]-'0';
	}
	//printa(a, 0, 1)
	COMinit();
	ll ans = 0;
	zep(i, 0, d){
		//print(ans);
		if(i == 0){
			if(d-1 >= k-1){
				ans += (a[i]-1)*COM(d-1, k-1)*pow(9, k-1);
			}
			if(d-1 >= k){
				ans += COM(d-1, k)*pow(9, k);
			}
			k--;
		}
		else{
			if(a[i] > 0){
				if(d-1-i >= k-1){
					ans += (a[i]-1)*COM(d-1-i, k-1)*pow(9, k-1);
				}
				if(d-1-i >= k){
					ans += COM(d-1-i, k)*pow(9, k);
				}
				k--;
			}
		}
		
		if(k < 0){
			break;
		}
	
		if(k == 0 && i == d-1){
			ans++;
		}
	}
	print(ans)
	return 0;
}

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

int main() {
    string S;
    cin >> S;

    int i = -1;
    int j = -1;
    for (int k = 0; k < S.size(); k++) {
        if (S.at(k) == 'A' && i == -1 && j == -1) {
            i = k;
        } else if (S.at(k) == 'Z' && i != -1 && j < k) {
            j = k;
        }
    }
    cout << S.substr(i, j-i+1).size() << endl;
}


Measured memory_bytes: 772
#include <cstdint>
#include <vector>

using namespace std;

static bool aux(vector<uint32_t> &vec, uint32_t index, int32_t val)
{
  if (val == 0) return true;

  if (vec.size() == index || (val < 0)) {
    return false;
  }

  int32_t rem = val - vec[index];

  return aux(vec, index + 1, rem) || aux(vec, index + 1, val);
}

bool exausitve_search_search(vector<uint32_t> vec, int32_t val)
{
  return aux(vec, 0, val);
}

#if !defined(TEST)
#include <iostream>

static vector<uint32_t> array;

int32_t main()
{
  uint32_t num;
  cin >> num;

  for (uint32_t i = 0; i < num; i++) {
    uint32_t val;
    cin >> val;
    array.push_back(val);
  }

  cin >> num;

  for (uint32_t i = 0; i < num; i++) {
    uint32_t val;
    cin >> val;

    if (exausitve_search_search(array, val)) {
      cout << "yes" << endl;
    } else {
      cout << "no" << endl;
    }
  }

  return 0;
}

#endif

Measured memory_bytes: 3168
use proconio::input;

fn main() {
    input! {
        n:usize,
        a: [i64;n],
    }

    let mut ans: i64 = 0;
    let mut prev_height: i64 = 0;
    for i in 0..n {
        if a[i] - prev_height < 0 {
            ans += prev_height - a[i];
        } else {
            prev_height = a[i];
        }
    }
    println!("{}", ans)
}


Measured memory_bytes: 5556
/*
Unit Fraction Partition
https://onlinejudge.u-aizu.ac.jp/problems/1131
p,q <= 800 かつ a <= 12000 かつ n <= 7 
dfs, 全探索



*/
#include <iostream>
using namespace std;
#define int long long
int P,Q,A,N;

int dfs(int p,int q,int n,int t){

    if(P*q==p*Q)return 1;
    if(P*q<p*Q)return 0;
    if(N==n)return 0;

    int ret=0;

    for(int i=t;q*i<=A;i++){
        ret+=dfs(p*i+q,q*i,n+1,i);
    }
    return ret;
}

signed main(){
    while(cin>>P>>Q>>A>>N,P||Q||A||N)
        cout<<dfs(0,1,0,1)<<endl;
    return 0;
}


Measured memory_bytes: 3080
#include <iostream>
using namespace std;
int main(void){
 int N,p[50],x,i;
 cin>>N;
 for(i=1;i<=N;i++){cin >> p[i];}
x=0;
for(i=1;i<=N;i++){if(p[i]!=i){x=x+1;}}

if(x>2){cout<<"NO"<<endl;}else{cout<<"YES"<<endl;}
    return 0;
}


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

int h, w;
int x[80][80];
bool y[80][80][13000];

int main() {
    scanf("%d %d", &h, &w);
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) scanf("%d", &x[i][j]);
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int b;
            scanf("%d", &b);
            x[i][j] = abs(x[i][j] - b);
        }
    }
    
    y[0][0][x[0][0]] = true;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            for (int k = 0; k < 13000; k++) {
                if (!y[i][j][k]) continue;
                if (j < w - 1) {
                    y[i][j + 1][k + x[i][j + 1]] = true;
                    y[i][j + 1][abs(k - x[i][j + 1])] = true;
                }
                if (i < h - 1) {
                    y[i + 1][j][k + x[i + 1][j]] = true;
                    y[i + 1][j][abs(k - x[i + 1][j])] = true;
                }
            }
        }
    }
    
    for (int i = 0; i < 13000; i++) {
        if (y[h - 1][w - 1][i]) {
            printf("%d\n", i);
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 80512
def combi (a,b)
    $n=a
    $m=1
    answer=1
    b.times{
        answer=answer*$n/$m
        if answer>1000000009
            answer=answer%1000000009
            
         end   
        $n-=1
        $m+=1
        
    }
return answer


end

def kaizyou(s)
  $answer=1
  $k=1
  s.times{
     $answer=$answer* $k
      if $answer>1000000007
            $answer=$answer%1000000007
            
         end   
      
     $k+=1 
      
  }
  return   $answer
end





a,b=gets.split
a=a.to_i
b=b.to_i

if (a-b).abs>=2
    puts 0
    
elsif    a==b

   puts  (kaizyou(a)*kaizyou(a)*2)%1000000007
   
else  puts (kaizyou(a)*kaizyou(b))%1000000007
    


end



  
 
    
    
    


Measured memory_bytes: 3836
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int A,B,C,X;cin>>A>>B>>C>>X;
  ll ans = 0;
  repeat(a,A+1){
    repeat(b,B+1){
      repeat(c,C+1){
        ans += 500*a+100*b+50*c==X;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

bool is_prime(int k)
{
	for(int j=2;j*j<=k;j++){
		if(k%j==0) {
			return false;
		}
	}
    return true;
}

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main()
{
    // 入力
    ll N,M,Q;
    cin>>N>>M>>Q;

    ll L[M+1],R[M+1];
    for(int i=1;i<=M;i++){
    	cin>>L[i]>>R[i];
    }

    ll p[Q+1],q[Q+1];
    for(int i=1;i<=Q;i++){
    	cin>>p[i]>>q[i];
    }

    int stoplist[N+1][N+1];
    for(int i=1;i<=N;i++){
    	for(int j=1;j<=N;j++){
    		stoplist[i][j]=0;
    	}
    }

    for(int i=1;i<=M;i++){
    	for(int j=1;j<=L[i];j++){
    		// for(int k=R[i];k<=N;k++){
    			stoplist[j][R[i]]++;
    			// cout<<i<<j<<k<<endl;
    		// }
    	}
    }
    for(int i=1;i<=Q;i++){
    	int ans=0;
    	for(int j=p[i];j<=q[i];j++){
    		ans+=stoplist[p[i]][j];
    	}
    	cout<<ans<<endl;
    }

    return 0;
}

Measured memory_bytes: 6528