akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  ll N;
  cin>>N;
  VL X(11);
  X[0]=1;
  rep(i,10) X[i+1]=X[i]*26;
  VL Y(11);
  Y[0]=1;
  rep(i,10) Y[i+1]=Y[i]+X[i+1];
  int K;
  rep(i,11) if(N>=Y[i]) K=i+1;
  N-=Y[K-1];
  string ans="";
  rep(i,K){
    ans+=char('a'+N%26);
    N/=26;
  }
  reverse(all(ans));
  cout<<ans<<endl;
}


Measured memory_bytes: 3564
import java.util.Scanner;
import java.util.Stack;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        Stack<String> stack = new Stack<>();
        for (int i = 0 ; i < S.length() ; i++) {
            if (S.substring(i, i + 1).equals("S")) {
                stack.push("S");
            } else {
                if (stack.empty() || stack.peek().equals("T")) {
                    stack.push("T");
                } else {
                    stack.pop();
                }
            }
        }
        System.out.println(stack.size());
    }

}

Measured memory_bytes: 37860
def solve(string):
    n, *x = map(int, string.split())
    mid = n // 2
    x = [(i, _x) for i, _x in enumerate(x)]
    x = sorted(x, key=lambda x: x[1])
    ans = [(_x[0], x[mid][1]) if i < mid else (_x[0], x[mid - 1][1]) for i, _x in enumerate(x)]
    ans = sorted(ans, key=lambda x: x[0])
    return "\n".join([str(_x) for i, _x in ans])


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))


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

int main(){
    while(1){
        string str;
        cin >> str;
        if(str == "-") break;

        int m;
        cin >> m;
        for(int i=0; i<m; i++){
            int h_i;
            cin >> h_i;

            string s1, s2;
            s1 = str.substr(0, h_i);
            s2 = str.substr(h_i, str.size());
            str = s2.insert(s2.size(), s1);
        }
        cout << str << endl;
    }

    return 0;
}


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

#define rep(i,begin,end) for(int i=begin; i<end; i++)
#define revrep(i,begin,end) for(int i=begin; i>end; i--)
#define lld long long int

typedef struct node{
    lld x;
    lld h;
    lld imo;
}node;

int cmpAsc(const void* a, const void* b){
    lld x = ((node*)a)->x, y = ((node*)b)->x;
    if(x > y){
        return 1;
    }
    if(x < y){
        return -1;
    }
    return 0;
}

int main(){
    int n;
    lld d;
    lld a;
    scanf("%d %lld %lld", &n, &d, &a);
    d = 2*d;
    node m[n];
    rep(i, 0, n){
        lld x;
        lld h;
        scanf("%lld %lld", &x, &h);
        m[i].x = x;
        m[i].h = h;
        m[i].imo = 0;
    }
    qsort(m, n, sizeof(node), cmpAsc);
    int l, r, p;
    lld ans = 0;
    ans += (lld)(m[0].h + a - 1) / a;
    m[0].imo += (lld)(m[0].h + a - 1) / a * a;
    l = 0; r = n-1; p = (l+r+1)/2;
    while(l < r){
        p = (l + r +1)/2;
        if(m[p].x <= m[0].x + d){
            l = p;
        }else{
            r = p-1;
        }
    }
    p = (l + r +1)/2;
    if(p < n-1){
        m[p+1].imo -= (lld)(m[0].h + a - 1) / a * a;
    }

    /*printf("\n");
    rep(i, 0, n){
        printf("%lld ", m[i].imo);
    }
    printf("\n");*/

    rep(i, 1, n){
        m[i].imo += m[i-1].imo;
        if(m[i].h <= m[i].imo){
            continue;
        }else{
            //printf("--%d--\n", i);
            ans += (lld)(m[i].h - m[i].imo + a - 1) / a;
            lld buf = (lld)(m[i].h - m[i].imo + a - 1) / a * a;
            m[i].imo += buf;
            l = 0; r = n-1; p = (l+r+1)/2;
            while(l < r){
                p = (l + r +1)/2;
                if(m[p].x <= m[i].x + d){
                    l = p;
                }else{
                    r = p-1;
                }
            }
            p = (l + r +1)/2;
            if(p < n-1){
                m[p+1].imo -= buf;
            }
        }
    }
    printf("%lld", ans);

    /*printf("\n");
    rep(i, 0, n){
        printf("%lld ", m[i].imo);
    }*/

    return 0;
}

Measured memory_bytes: 9468
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>

using namespace std;

int n, k, a[2002][2002]{};

int main() {
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		int x, y;
		string s;
		cin >> x >> y >> s;
		if (s == "W")x += k;
		x %= k * 2; y %= k * 2;
		x++; y++;
		a[x][y]++;
	}
	for (int i = 1; i <= k * 2; i++) {
		for (int j = 1; j <= k * 2; j++) {
			a[i][j] += a[i][j - 1];
		}
	}
	for (int j = 1; j <= k * 2; j++) {
		for (int i = 1; i <= k * 2; i++) {
			a[i][j] += a[i - 1][j];
		}
	}
	int ans=0;
	for (int i = 0; i < k; i++) {
		for (int j = 0; j < k; j++) {
			int sum = n - a[k * 2][j + k] - a[i + k][k * 2] + a[i + k][j + k] * 2 - a[i + k][j] - a[i][j + k] + a[i][j] * 2 + a[k * 2][j] - a[i + k][j] + a[i][k * 2] - a[i][j + k];
			ans = max(ans, max(sum,n-sum));
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 15872
N=int(input())
S=input()

ans=0

for i in range (1000):
    tempS=S
    pin=str(i).zfill(3)
    t1=pin[0]
    t2=pin[1]
    t3=pin[2]
    if tempS.count(t1)>=1:
        tempS=tempS[tempS.find(t1)+1:]
    else:
        continue

    if tempS.count(t2)>=1:
        tempS=tempS[tempS.find(t2)+1:]
    else:
        continue

    if tempS.count(t3)>=1:
        ans+=1
    else:
        continue

print(ans)



Measured memory_bytes: 9308
#include "stdio.h"
#include "math.h"

#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

const int INF = 10000000;
using namespace std;
typedef long long  ll;

/** Problem0259 : All Numbers Lead to 6174 **/
int main()
{
	string s;
	int  min, max, num[4], n;
	
	while (cin>>s, s!="0000") {
		n=1;
		if (s=="6174") {
			cout << 0 << endl;
			continue;
		} else if (s[0]==s[1] && s[0]==s[2] && s[0]==s[3]) {
			cout << "NA" << endl;
			continue;
		}
		while (1) {
			min=0; max=0;
			fill(num, num+4, 0);
			rep(i, s.length()) {
				num[i] = s[i]-'0';
			}
			sort(num, num+4);
			rep(i, 4) {
				min*=10;
				min+=num[i];
			}
			reverse(num, num+4);
			rep(i, 4) {
				max*=10;
				max+=num[i];
			}
			int nn = max-min;
			if (nn == 6174) {
				cout << n << endl;
				break;
			} else {
				s="";
				rep(i, 4) {
					s+= nn%10;
					nn/=10;
				}
			}
			n++;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1208
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include<stdio.h>
#include<cstdlib>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int a[4];
    int s;
    for(int i=0;i<4;i++){
        cin >> a[i];
    }
    sort(a,a+4);

    for(int i=0;i<n-4;i++){
        cin >> s;
        if(s<a[3]){
            a[3]=s;
            sort(a,a+4);
            
        }
    }
    string str[4];
    for(int i=0;i<4;i++){
        str[i]=to_string(a[i]);
    }
    
    
    long long int ans[12];
    int k=0;
    for(int i=0;i<4;i++){
        for(int j=0;j<4;j++){
            if(i!=j){
                string s=str[i]+str[j];
                ans[k]=atoi(s.c_str());
                k++;
            }
        }
    }

    
    sort(ans,ans+12);
    cout << ans[2] << endl;
    
    
    return 0;
}



Measured memory_bytes: 3244
//written by: rishav2416
#include <bits/stdc++.h>
#define ll long  long
#define lli long long int
#define ld long double
#define mod 1000000007
#define max_char 128
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define lbd lower_bound
#define ubd upper_bound
#define PI 3.141592653589793238
#define pf push_front
#define all(x) x.begin(),x.end()
#define input(arr,n) for(ll c1=0;c1<n;c1++)cin>>arr[c1];
#define arrinit(arr,n,k) for(ll c1=0;c1<n;c1++) arr[i]=k;
#define rep(i,a,n) for( ll i=a ; i<n ; i++)
#define revrep(i,a,n) for(ll i=a; i>=n ; i--)
#define mems(x, y) memset(x, y, sizeof(x))
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define INF 1e18a



ll power(ll base,ll pow, ll mo)
{
   ll res=1;
   while(pow)
   {
        if (pow%2!=0)  res=(res*base)%mo;
        base=(base*base)%mo;
        pow/=2;
   }
   return res;
}


std::string str="All Good Till Here";

/////////////////////////////////////////////////////////////////////////////////

int32_t main()
{
    fastio
	ll tt,i,j,n,x;
	//cin>>tt;
  tt=1;
	while(tt--)
	{
    cin>>n;
    x=n%10;
    string str;
    if(x==2 || x==4 || x==5 || x==7 ||x==9)
      str="hon";
    else if(x==0 || x==1 || x==6 || x==8)
      str="pon";
    else
      str="bon";
    cout<<str<<"\n";
	}
    return 0;
}


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

int main() {
  
  int N;
  cin >> N;
  
  vector<int> A(N);
  
  for(int i=0; i<N; i++){
    cin >> A.at(i);
  }
    
  int cnt=0;
  
  while(true){
    bool ans = false;
    for(int i=0; i<N; i++){
      if(A.at(i) % 2 != 0){
        ans = true;
      }  
    }
  
    if(ans){
      break;
    }
  
    for(int i=0; i<N; i++){
      A.at(i) /= 2;
    }
  
    cnt++;
    
  }
  
  cout << cnt << endl;
  
}


Measured memory_bytes: 3632
#

import sys
input=sys.stdin.readline

def main():
    N=int(input())
    A=list(map(int,input().split()))
    m=1000
    s=0
    for i in range(N-1):
        if A[i]>A[i+1]:
            m+=s*A[i]
            s=0
        else:
            n=int(m//A[i])
            m-=n*A[i]
            s+=n
    m+=s*A[-1]
    print(m)
    
if __name__=="__main__":
    main()


Measured memory_bytes: 9116
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <numeric>




typedef long long ll;
#define PI 3.14159265359
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define mp make_pair
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define decp(n) cout<<fixed<<setprecision((int)n)
#define _GLIBCXX_DEBAC
#include <functional>
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/
//copy(v1.begin(), v1.end(), back_inserter(v2));
using namespace std;

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

ll lcm(ll a, ll b) {
	ll c;
	c = a * b / gcd(a, b);
	return c;
}

int sort_greater(int m, int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(), greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
	return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

int a_z()
{
	for (int i = 0; i <= ('Z' - 'A'); i++) {
		cout << (char)('A' + i);
	}
	return 0;
}

int selecttionsort(int a[], int n) {
	int t, sw = 0, minj;
	for (int i = 0; i < n - 1; i++) {
		minj = i;
		for (int j = 0; j < n - 1; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		t = a[i]; a[i] = a[minj]; a[minj] = t;
		if (i != minj) sw += 1;

	}
	return sw;
}

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

const ll mod = 1000000007;

map<string, int> memo;

using P=pair<int, int>;
/*void dfs(int v, int p = -1) {
	for (int u : to[v]) {
		if (u == p) continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}*/
ll findIndex(int value, vector<ll> a)
{

	for (ll i = 0; i < (ll)a.size(); i++) {
		if (a[i] == value) {
			return i;
		}
	}
	return -1;
}

ll nCr(ll n, ll r) {
	ll a = 1;
	for (ll i = n; i > n - r; --i) {
		a = a * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		a = a / i;
	}
	return a;
}

void comb(vector<vector <long long int> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (ll j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
		}
	}
}



int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int x = c - a, y = d - b;
	cout << c - y << " " << d + x << " " << a - y << " " << b + x;
	return 0;
}













Measured memory_bytes: 256
import java.util.Scanner;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int M = scan.nextInt();
        //Build graph
        Map<Integer, List<Integer>> graph = new HashMap<>();
        for(int i = 0 ; i < M ; i++){
            int source = scan.nextInt();
            int target = scan.nextInt();
            graph.putIfAbsent(source, new ArrayList<>());
            graph.get(source).add(target);
        }

        int longestPath = 0;
        int[] longest = new int[N+1];
        Arrays.fill(longest, -1);
        for(int vertex = 1 ; vertex <= N ;vertex++){
            if(longest[vertex] == -1) {
                longestPath = Math.max(longestPath, dfs(graph, vertex, longest));
            }
        }
        System.out.println(longestPath);
    }

    private static int dfs(Map<Integer, List<Integer>> graph, Integer vertex, int[] cache) {
        if(cache[vertex] != -1) {
            return cache[vertex];
        }

        int longestFromHere = 0;
        if(graph.get(vertex) != null) {
            for(Integer neighbour : graph.get(vertex)) {
                longestFromHere = Math.max(longestFromHere, 1+dfs(graph, neighbour, cache));
            }
        }
        cache[vertex] = longestFromHere;
        return cache[vertex];
    }
}


Measured memory_bytes: 106540
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  
int main() {
  string s;
  cin >> s;
  ll k=s.size();
  ll a=0,b=0,c=0,d=0;
  rep(i,k){
    if(s[i]=='S'){
      a++;
    }
    else if(s[i]=='N'){
      b++;
    }
    else if(s[i]=='W'){
      c++;
    }
    else
      d++;
  }
  if(a*b==0&&max(a,b)!=0){
    cout << "No" << endl;
  }
  else if(c*d==0&&max(c,d)!=0){
    cout << "No" << endl;
  }
  else
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

long long inp_c, inp_n, inp_c2, inp_n2, i1, i2, out_s;

bool marker[102];

long long readNumber() {
	long long temp_func;
	scanf("%lld", &temp_func);
	return temp_func;
};
long long printNumber(long long temp_func) {
	printf("%lld ", temp_func);
	return 0;
};

int main() {
	
	inp_n = readNumber();
	
	inp_c = readNumber();
	
	for (i1 = 1; i1 <= inp_c; i1++) {
		
		inp_c2 = readNumber();
		
		for (i2 = 1; i2 <= inp_c2; i2++) {
			
			inp_n2 = readNumber();
			
			marker[inp_n2] = true;
			
		};
		
	};
	
	for (i1 = 1; i1 <= inp_n; i1++) {
		
		out_s += !marker[i1];
		
	};
	
	printNumber(out_s);
	
}

Measured memory_bytes: 1732
class Dijkstra():
    """ ダイクストラ法
    重み付きグラフにおける単一始点最短路アルゴリズム

    * 使用条件
        - 負のコストがないこと
        - 有向グラフ、無向グラフともにOK

    * 計算量はO(E*log(V))

    * ベルマンフォード法より高速なので、負のコストがないならばこちらを使うとよい
    """
    class Edge():
        """ 重み付き有向辺 """
        def __init__(self, _to, _cost):
            self.to = _to
            self.cost = _cost

    def __init__(self, V):
        """ 重み付き有向辺
        無向辺を表現したいときは、_fromと_toを逆にした有向辺を加えればよい

        Args:
            V(int): 頂点の数
        """
        self.G = [[] for i in range(V)]  # 隣接リストG[u][i] := 頂点uのi個目の隣接辺
        self._E = 0  # 辺の数
        self._V = V  # 頂点の数

    @property
    def E(self):
        """ 辺数
        無向グラフのときは、辺数は有向グラフの倍になる
        """
        return self._E

    @property
    def V(self):
        """ 頂点数 """
        return self._V

    def add(self, _from, _to, _cost):
        """ 2頂点と、辺のコストを追加する """
        self.G[_from].append(self.Edge(_to, _cost))
        self._E += 1

    def shortest_path(self, s):
        """ 始点sから頂点iまでの最短路を格納したリストを返す
        Args:
            s(int): 始点s
        Returns:
            d(list): d[i] := 始点sから頂点iまでの最短コストを格納したリスト。
                     到達不可の場合、値はfloat("inf")
        """
        import heapq
        que = []  # プライオリティキュー（ヒープ木）
        d = [10**15] * self.V
        d[s] = 0
        heapq.heappush(que, (0, s))  # 始点の(最短距離, 頂点番号)をヒープに追加する

        while len(que) != 0:
            cost, v = heapq.heappop(que)
            # キューに格納されている最短経路の候補がdの距離よりも大きければ、他の経路で最短経路が存在するので、処理をスキップ
            if d[v] < cost: continue

            for i in range(len(self.G[v])):
                # 頂点vに隣接する各頂点に関して、頂点vを経由した場合の距離を計算し、今までの距離(d)よりも小さければ更新する
                e = self.G[v][i]  # vのi個目の隣接辺e
                if d[e.to] > d[v] + e.cost:
                    d[e.to] = d[v] + e.cost  # dの更新
                    heapq.heappush(que, (d[e.to], e.to))  # キューに新たな最短経路の候補(最短距離, 頂点番号)の情報をpush
        return d

import sys

input=sys.stdin.readline

N,M=map(int,input().split())
pro=Dijkstra(N)
edge=[[] for i in range(N)]
for i in range(M):
    a,b=map(int,input().split())
    pro.add(a-1,b-1,1)
    pro.add(b-1,a-1,1)
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

data=pro.shortest_path(0)

ans=[]
for i in range(1,N):
    for j in edge[i]:
        if data[j]==data[i]-1:
            ans.append(j)
            break
    else:
        print("No")
        exit()

print("Yes")
for i in range(N-1):
    print(ans[i]+1)

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

int main() {
    int R,G,B,N;
    cin >> R >> G >> B >> N;



    int a = N / R;
    int Rr, Gg, Bb, x,b;
    int ans = 0;
    for (int i = 0; i < a+1; i++)
    {
        Rr = R * i;
        b = (N-Rr)/G;
        for (int j = 0; j < b+1; j++)
        {
            Gg = G * j;
            x = N - Rr - Gg;
            if (x < 0)
            break;
            if (x % B == 0)
            ans += (x % B) + 1;

        }
    

    }
    cout << ans << endl; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using pi=pair<int,int>;
#define mp make_pair
main(){
  int h,w,k,r=0;
  cin>>h>>w;
  vector<vector<int>> c(10,vector<int>(10));
  for(auto& v:c)for(auto& i:v)cin>>i;
  vector<int> cost(10);
  auto f=[](pi a,pi b){return a.second>b.second;};
  priority_queue<pi,vector<pi>,decltype(f)> que(f);
  vector<bool> vis(10,false);
  que.push(mp(1,0));
  while(!que.empty()){
    pi p=que.top();que.pop();
    if(vis[p.first])continue;
    vis[p.first]=true;
    cost[p.first]=p.second;
    for(int i=0;i<10;++i)if(!vis[i])que.push(mp(i,p.second+c[i][p.first]));
  }
  for(int i=0;i<h*w;++i){
    cin>>k;
    r+=(k<0?0:cost[k]);
  }
  cout<<r;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    for (int i = 0; i < n; i++) cin >> p[i];
    vector<int> order(n + 1, 0);
    for (int i = 0; i < n; i++) order[p[i]] = i;
    long long ans = 0;
    set<int> s;
    s.insert(-1);
    s.insert(-2);
    s.insert(1e6);
    s.insert(1e6 + 1);
    for (int i = n; i > 0; i--){
        int x = order[i];
        long long c = 0;
        vector<int> l(2);
        vector<int> r(2);
        s.insert(x);
        {
            auto itr = s.find(x);
            --itr; l[0] = *itr;
            --itr; l[1] = *itr;
        }
        {
            auto itr = s.find(x);
            ++itr; r[0] = *itr;
            ++itr; r[1] = *itr;
        }
        if (l[0] < 0) l[0] = - 1;
        if (l[1] < 0) l[1] = - 1;
        if (r[0] >= 1e6) r[0] = n;
        if (r[1] >= 1e6) r[1] = n;
        c += (long long)(x - l[0]) * (r[1] - r[0]);
        c += (long long)(l[0] - l[1]) * (r[0] - x);
        ans += c * i;
    }
    cout << ans << endl;
}

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

int main() {
  string s;
  while(cin >> s) {
    int a[10];
    for(int i=0; i<10; i++) a[i]=(int)s[i]-48;
    for(int i=0; i<10; i++) {
      for(int j=0; j<10-i-1; j++) {
	int x=a[j], y=a[j+1];
	a[j] = (x+y)%10;	
      }
    }
    cout << a[0] << endl;
  }
  return 0;
}


Measured memory_bytes: 1180
#include<stdio.h>
#include<cstdio>
#include<iostream>
#include<cmath>
#include<bits/stdc++.h>
using namespace std;


int main()
{
	int i,n;
	cin>>n;
	char ss[111];
	int a,b,y,x;
	a=b=x=y=0;
	while(n--){
		scanf("%s",&ss);
		if(ss[0]=='B'&&ss[strlen(ss)-1]!='A')	b++;
		else if(ss[strlen(ss)-1]=='A'&&ss[0]!='B')	a++;
		else if(ss[0]=='B'&&ss[strlen(ss)-1]=='A')	y++;
		for(i=0;i<strlen(ss);i++){
			if(ss[i]=='A'&&ss[i+1]=='B')
				x++;
		}
	}
	if(y==0) cout<<x+min(a,b)<<endl;
	else if(y!=0&&a==b&&a!=0)	cout<<a+y+x<<endl;
	else if(y!=0&&a==b&&a==0)	cout<<x+y-1<<endl;
	else if(y!=0&&a!=b)	cout<<min(a,b)+x+y<<endl;
	return 0;
}


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

int times = 0;

void insertion_sort(vector<int> &A,int n,int g)
{
	int v, j;
	for (int i = g; i < n; i++)
	{
		v = A[i];
		j = i - g;
		while (j >= 0 && A[j] > v) {
			A[j + g] = A[j];
			j -= g;
			times++;
		}
		A[j + g] = v;
	}
}

int main(void)
{
	int n, k = 1;
	cin >> n;
	vector<int>A(n);
	vector<int>G;
	for (int i = 0; i < n; i++) {
		cin >> A[i];
	}
	for (int i = 0; k <= n; i++) {
		G.push_back(k);
		k = 3 * k + 1;
	}
	for (int i = G.size() - 1; i >= 0; i--) {
		insertion_sort(A, n, G[i]);
	}
	cout << G.size() << endl;
	for (int i = G.size() - 1; i >= 0; i--) {
		cout << G[i];
		if (i != 0)
			cout << " ";
		else
			cout << endl;
	}
	cout << times << endl;
	for (int i = 0; i < n; i++) {
		cout << A[i] << endl;
	}
	return 0;
}


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

int main() {
  char c;cin>>c;
  if(c=='a'||c=='i'||c=='u'||c=='e'||c=='o') cout << "vowel" << endl;
  else cout << "consonant" << endl;
}


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

using namespace std;

int main() {
    string c[2];
    cin >> c[0] >> c[1];
    cout << ((c[0][2] == c[1][0] && c[0][1] == c[1][1] && c[0][0] == c[1][2]) ? "YES" : "NO") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 99999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m;i>n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl
#define Vecpr(K,L1,L2,N) vector<pair<L1,L2>> K(N)
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,R) vector<vector<L>> K(N, vector<L>(M,R))
#define mod 1000000007
#define MAX 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
   lli A,B,C,N,M,K,L,R,sum=0,num=0;
   cin >> N >> M;
   N=N-M;
   sum=100*N+1900*M;
   M=pow(2,M);
   Out(sum*M);
}

Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	lines := []int{
		nextInt(),
		nextInt(),
		nextInt(),
	}
	sort.Ints(lines)
	fmt.Println(lines[0] * lines[1] / 2)
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func abs(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func pow(p, q int) int {
	res := p
	if q == 0 {
		return 1
	}
	for i := 0; i < q-1; i++ {
		res *= p
	}
	return res
}

func MinOf(vars ...int) int {
	min := vars[0]
	for _, i := range vars {
		if min > i {
			min = i
		}
	}
	return min
}

func MaxOf(vars ...int) int {
	max := vars[0]
	for _, i := range vars {
		if max < i {
			max = i
		}
	}
	return max
}

func gcdof2numbers(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcdof2numbers(b, a%b)
}

func lcmof2numbers(a int, b int) int {
	return a / gcdof2numbers(a, b) * b
}

// マイナスの場合は考慮していない
func fuctorial(a int) int {
	if a == 1 || a == 0 {
		return 1
	} else {
		return fuctorial(a-1) * a
	}
}

func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}

// 素因数分解したmapを返す
func primeFuctorize(n int) map[int]int {
	pf := map[int]int{}
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			pf[i]++
			n /= i
		}
	}
	if n != 1 {
		pf[n]++
	}
	return pf
}


Measured memory_bytes: 640
import Control.Applicative ((<$>))
import Control.Monad (replicateM, unless, forM_)
import Data.Vector (Vector, (!))
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM

main :: IO ()
main = do
  n <- readLn
  unless (n == 0) $ do
    solve n <$> replicateM n (map read <$> words <$> getLine) >>= print
    main

solve :: Int -> [[Int]] -> Int
solve n xs = f v rt
  where v = V.create $ do
          v <- VM.replicate n (Node (-1) (-1) (-1) (-1) (-1))
          forM_ (zip [0 .. ] xs) $ \(i, [p, q, r, b]) -> do
            (Node _ _ pt _ _) <- VM.read v i
            let g = gcd p q
            VM.write v i (Node (p `div` g) (q `div` g) pt (r-1) (b-1))
            unless (r == 0) $ do
              (Node p q _ lc rc) <- VM.read v (r-1)
              VM.write v (r-1) (Node p q i lc rc)
            unless (b == 0) $ do
              (Node p q _ lc rc) <- VM.read v (b-1)
              VM.write v (b-1) (Node p q i lc rc)
          return v
        Just rt = V.findIndex (\nd -> pt nd == (-1)) v
        f v i | i == (-1) = 1
              | otherwise = l `div` p + l `div` q
          where (Node p q _ lc rc) = v ! i
                lw = f v lc
                rw = f v rc
                l = lcm (p * lw) (q * rw)

data Node = Node {p :: Int, q :: Int, pt :: Int, lc :: Int, rc :: Int } deriving Show



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

using namespace std;

long long ans;

int b[11];
long long n, m;

void DFS(int d, long long now, long long s) {
	if (d > m) {
		s += now;
		ans += s;
		return;
	}
	DFS(d + 1, b[d], s + now);
	if (d > 1) DFS(d + 1, now * 10 + b[d], s);
}

int main() {
	scanf("%lld", &n);
	m = 0;
	while (n) {
		b[++m] = n % 10;
		n /= 10;
	}
	reverse(b + 1, b + m + 1);
	DFS(1, 0, 0);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define rollcall cout << "I'm Sucu." << endl;
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
      }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
// typedef
typedef complex<double> Point;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;
const int MAX = 5e5;


signed main(){
   int a, b, c;
   scanf("%lld%lld%lld", &a, &b, &c);
   int ans = b/c-a/c;
   if(a%c == 0)ans++;
   printf("%lld\n", ans);
  return 0;
}










Measured memory_bytes: 256
import math

a, b, h, m = map(int, input().split())

rad_h = 0
rad_m = 0
rad_clock = 0
parts_cos = 0
ans = 0


rad_h = h * 30 + m * 0.5
rad_m = m * 6
if rad_h < rad_m:
    rad_clock = rad_m - rad_h
elif rad_h > rad_m:
    rad_clock = rad_h - rad_m
else:
    rad_clock = 0


parts_cos = 2 * a * b * (math.cos(math.radians(rad_clock)))
ans = math.sqrt(a**2 + b**2 - parts_cos)
print(ans)


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

int main() {
	int i;
	int f;
	string s, t;
	vector<char> bs, bt, btt;

	cin >> s;
	cin >> t;

	for (i = 0; i < (int)s.size(); i++) {
		bs.push_back(s[i]);
	}
	for (i = 0; i < (int)t.size(); i++) {
		bt.push_back(t[i]);
	}

	sort(bs.begin(), bs.end());
	sort(bt.begin(), bt.end());

	for (i = (int)bt.size()-1; i >= 0 ; i--) {
		btt.push_back(bt[i]);
	}

	f = 0;
	if (s.size() <= t.size()) {
		for (i = 0; i < (int)s.size(); i++) {
			if (bs<btt) {
				cout << "Yes" << endl;
				f = 1;
				break;
			}
			else if (bs > btt) break;
		}
		if (f == 0)	cout << "No" << endl;
	}
	else {
		for (i = 0; i < (int)t.size(); i++) {
			if (bs<btt) {
				cout << "Yes" << endl;
				f = 1;
				break;
			}
			else if (bs > btt) break;
		}
		if (f == 0)	cout << "No" << endl;
	}

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();

		String[] s = {sc.next(), sc.next(), sc.next()};

		for(int i = 0;i < 3; i++) {
			sb.append(s[i].substring(i, i+1));
		}

		System.out.println(sb);
	}
}

Measured memory_bytes: 35592
data class Relate(val x: Int, val y: Int)

fun main(args: Array<String>) {
    val (n, k) = readIntegerList()
    val aList = readIntegerList()

    var ans = Long.MAX_VALUE
    for (state in 0 until (1 shl n)) {
        if (Integer.bitCount(state) < k) {
            continue
        }

        var tmp = 0L
        var currentMaxHeight = 0
        for (i in 0 until n) {
            if (((state shr i) and 1) == 1) {
                if (aList[i] <= currentMaxHeight) {
                    tmp += currentMaxHeight - aList[i] + 1
                }
                currentMaxHeight = Math.max(currentMaxHeight + 1, aList[i])
            } else {
                currentMaxHeight = Math.max(currentMaxHeight, aList[i])
            }
        }

        ans = Math.min(ans, tmp)
    }

    println(ans)
}

//fun countOneBits(state: Int, bitLength: Int): Int {
//    var count = 0
//    for (i in 0 until bitLength) {
//        if (((state shr i) and 1) == 1) {
//            count++
//        }
//    }
//    return count
//}




fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)


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

int main(){
    int x,y,g[13]={0,1,3,1,2,1,2,1,1,2,1,2,1};
    cin >> x >>y;
    if(g[x]==g[y]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  vector<ll> a(5);
  REP(i, 5) { cin >> a[i]; }
  ll ans = 1e18;
  REP(i, 5) {
    ll t = 0;
    REP(j, 5) {
      if (j == i) {
        t += a[j];
      } else {
        t += (a[j] + 9) / 10 * 10;
      }
    }
    ans = min(ans, t);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<string>
#include<cstring>
using namespace std;
 int main()
 {
 	 char a[100],b[100],c[100];
 	 int a1,b1,c1;
 	 scanf("%s %s %s",a,b,c);
 	 a1 = strlen(a);
 	 b1 = strlen(b);
 	 c1 = strlen(c);
 	 if (a[a1-1] == b[0] && b[b1-1] == c[0])
 	 	 {
 	 	 	 printf("YES\n");
		 }
		 else printf("NO\n");
		 return 0;
 }

Measured memory_bytes: 128
import numpy as np

n,m = map(int,input().split())
a=[0] * n
b=[0] * n
for i in range(n):
    a[i],b[i] = map(int,input().split())

mk = np.array([a,b])
#print(m)
index = np.argsort(mk)
#print(index)
mn = np.array([mk[0,index[0,:]],mk[1,index[0,:]]])
#print(mn)

sum = 0
for i in range(n):
    if mn[1][i] <= m:
        sum += mn[0][i] * mn[1][i]
        m = m - mn[1][i]

    else:
        sum += mn[0][i] * m
        break
print(sum)

Measured memory_bytes: 26204
#include <stdio.h>

typedef struct
{
    char suit, value;
} Card;

void bubble(Card A[], int N)
{
    int i, j;
    Card t;
    for (i = 0; i < N; i++)
    {
        for (j = N - 1; j >= i; j--)
        {
            if (A[j].value < A[j - 1].value)
            {
                t = A[j];
                A[j] = A[j - 1];
                A[j - 1] = t;
            }
        }
    }
}

void selection(Card A[], int N)
{
    int i, j, minj;
    Card t;
    for (i = 0; i < N; i++)
    {
        minj = i;
        for (j = i; j < N; j++)
        {
            if (A[j].value < A[minj].value)
                minj = j;
        }
        t = A[i];
        A[i] = A[minj];
        A[minj] = t;
    }
}

void print(Card A[], int N)
{
    int i;
    for (i = 0; i < N; i++)
    {
        if (i > 0)
            printf(" ");
        printf("%c%d", A[i].suit, A[i].value);
    }
    printf("\n");
}

int isStable(Card C1[], Card C2[], int N)
{
    int i;
    for (i = 0; i < N; i++)
    {
        if (C1[i].suit != C2[i].suit)
            return 0;
    }
    return 1;
}

/* オリジナル関数を追加 */
void str2Card(Card *t, char str[])
{
    t->suit = str[0];
    t->value = str[1] - '0';
}

int main(void)
{
    Card C1[100], C2[100];
    int N, i;
    char str[3];

    scanf("%d", &N);
    for (i = 0; i < N; i++)
    {
        scanf("%s", str);
        str2Card(&C1[i], str);
    }

    for (i = 0; i < N; i++)
        C2[i] = C1[i];

    bubble(C1, N);
    selection(C2, N);

    print(C1, N);
    printf("Stable\n");
    print(C2, N);
    if (isStable(C1, C2, N))
    {
        printf("Stable\n");
    }
    else
    {
        printf("Not stable\n");
    }

    return 0;
}


Measured memory_bytes: 2104
#include <stdio.h>
#include <string.h>
#define MIN(x, y) (((x) > (y)) ? (y) : (x))
#define ABS(x) ((x) >= 0 ? (x) : (-(x)))


int main()
{
  long long a, b, n;
  scanf("%lld %lld %lld", &a, &b, &n);
  if (n >= b) {
    printf("%lld", (b - 1) * a / b);
  } else {
    printf("%lld", n * a / b);
  }
  return 0;
}

Measured memory_bytes: 2156
import java.util.*;

class Main{
  public static void main(String args[]){
    Scanner scan = new Scanner(System.in);
    long n = scan.nextLong();
    long k = scan.nextLong();
    long sum = 0;
    long[] amari1 = new long[2];
    long a;
    int c=1;
    /*for(int i = 1;i <= n;i++){
      amari = i%k;
      if(amari1[amari] == 1){
        for(int l=0;l < k;l++){
          c +=amari1[l];
        }
        if(c == k){
          break;
        }
        c = 0;
        continue;
      }else{
        amari1[amari] = 1;
        a = (n - amari)/k;
        b = (n -(k-amari))/k;
        sum += a*a*b*2;
      }
    }*/

    if(k == (k/2)*2){
      amari1[0] = 0;
      amari1[1] = k/2;
      c=2;
    }
    for(int l = 0;l < c;l++){
    a = (n+amari1[l])/k;
    sum += (a*a*a);
  }

    System.out.println(sum);


  }
}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)

#define endl '\n'
#define pb emplace_back
#define mkp make_pair
#define p_q priority_queue
#define INF 2000000000
#define PI 3.1415926
#define coutdb cout << fixed << setprecision(10)

const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};
const long long MOD = 1e9+7;

// typedef long long ll;
#define int long long

template <typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

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

  int N, p[20]; cin >> N;
  REP(i, N) cin >> p[i];
  int ans = 0;
  REP(i, N-2){
    if(max({p[i], p[i+1], p[i+2]}) != p[i+1] and min({p[i], p[i+1], p[i+2]}) != p[i+1]) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, s, n)    for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...)  type __VA_ARGS__; read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream& operator>> (istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x): x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

string N;
int K;

i64 memo[105][2][5];

i64 dp(int k = 0, bool tight = true, int cnt = 0) {
    if (cnt > K) return 0;
    if (k >= N.length()) return cnt == K;

    auto &ret = memo[k][tight][cnt];
    if (~ret) return ret;

    ret = 0;
    const int x = N[k] - '0';
    const int r = (tight ? x : 9);
    rep(i, 0, r+1) {
        ret += dp(k+1, tight && (i == r), cnt + (i != 0));
    }

    return ret;
}

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

    read(N, K);
    memset(memo, -1, sizeof(memo));

    print(dp());

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        while (true) {
            int n = Integer.parseInt(sc.next());
            int x = Integer.parseInt(sc.next());

            if (n == 0 && x == 0) break;

            int sum = 0;
            for (int i = 1; i <= n - 2; i++) {
                for (int j = i + 1; j <= n - 1; j++) {
                    for (int k = j + 1; k <= n; k++) {
                        if (i + j + k == x) sum++;
                    }
                }
            }
            System.out.println(sum);
        }
    }
}

Measured memory_bytes: 26548
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;

#define len length()
#define sz size()
#define rep(i, n) for(int i = 0; i < n; i++)
#define srt(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define veci(a, n) vector<int> a(n)
#define vecs(a, n) vector<string> a(n)
#define psb(a) push_back(a)
#define ppb pop_back()
#define sp(n) cout << setprecision(n) << fixed
#define fst(s) s.at(0)
#define lst(s) s.at(s.len - 1)

bool sqrt_check(long long n){
    if(n == int(pow(int(sqrt(n)), 2))) return true;
    else return false;
}

int main(){
    int a, b;
    cin >> a >> b;
    int n;
    if((1 <= b) && (b <= 9)) n = a * 10 + b;
    else if((10 <= b) && (b <= 99)) n = a * 100 + b;
    else n = a * 1000 + b;

    if(sqrt_check(n)) cout << "Yes" << endl;
    else cout << "No" << endl;
    /*cout << "n:" << n << endl;
    cout << "sqrt(n):" << sqrt(n) << endl;
    cout << "int(sqrt(n)):" << int(sqrt(n)) << endl;
    cout << "int(pow(int(sqrt(n)), 2)):" << int(pow(int(sqrt(n)), 2)) << endl;*/
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=500005,inf=0x3f3f3f3f;
int read(){
	int f=1,g=0;
	char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int n,m,L,cnt,h[N],b[N],sl[N],sr[N];
ll ans;
typedef pair<int,int> pr;
priority_queue<pr,vector<pr>,greater<pr> > f;
struct node{int val,l,r,pre,nex,col;}a[N];
int getsum(int *s,int l,int r){return s[r]-s[l-1];}
void split(int x){
	int cur=x;m=0;
	while (a[x].val==a[cur].val){
		b[++m]=cur;
		sl[m]=sl[m-1]+a[cur].l;
		sr[m]=sr[m-1]+a[cur].r;
		cur=a[cur].nex;
	}
}
int getpre(int x){while(a[a[x].pre].val==a[x].val) x=a[x].pre;return x;}
void recalc(){
	for (int i=1,j=1;i<=m;i++){
		while ((j-i+1<L)||(a[b[i]].col==a[b[j]].col)) j++;
		if (j<=m) ans+=(ll)a[b[i]].l*getsum(sr,j,m);
		else break;
	}
}
void printch(int x){
	while (a[x].pre) x=a[x].pre;
	for (;x;x=a[x].nex) printf("%d ",x);
	printf("\n");
}
int main(){
	n=read();L=read();ans=cnt=n;
	for (int i=1;i<=n;i++){
		a[i].val=read();a[i].l=a[i].r=1;
		a[i].pre=i-1;a[i].nex=i+1;h[i]=1;
		f.push(make_pair(a[i].val,i));
	}
	a[n].nex=0;
	for (int i=1,j;i<=n;i=j){
		for (j=i;a[i].val==a[j].val;j++);
		int len=j-i;
		if (len>=L) ans+=(ll)(len-L+1)*(len-L+2)/2;
		while (i<j){a[i].col=j-1;i++;}
	}
	while (1){
		while (!h[f.top().second]) f.pop();
		int x=getpre(f.top().second),y;f.pop();
		//printch(x);
		if (a[x].val>=inf) break;
		split(x);
		for (int i=1;i<=m;i++) h[b[i]]=0;
		x=a[b[1]].pre,y=a[b[m]].nex;
		if (m<L){
			a[++cnt].val=inf;
			a[cnt].pre=x;a[cnt].nex=y;
			a[cnt].col=cnt;
			if (x) a[x].nex=cnt;
			if (y) a[y].pre=cnt;
			h[cnt]=1;f.push(make_pair(a[cnt].val,cnt));
			continue;
		}
		recalc();
		int r=m/L;
		for (int i=1;i<=r;i++){
			a[cnt+i].val=a[b[1]].val+1;
			int tl=m-(r-i+1)*L+1,tr=max(1,tl-(L-1));
			a[cnt+i].l=getsum(sl,tr,tl);
			tl=i*L,tr=min(m,tl+L-1);
			a[cnt+i].r=getsum(sr,tl,tr);
			a[cnt+i].pre=(i!=1) ? (cnt+i-1) : x;
			a[cnt+i].nex=(i!=r) ? (cnt+i+1) : y;
			a[cnt+i].col=cnt+r;
			h[cnt+i]=1;f.push(make_pair(a[cnt+i].val,cnt+i));
		}
		if (x) a[x].nex=cnt+1;
		if (y) a[y].pre=cnt+r;
		cnt+=r;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 20976
#include <iostream>
#include <algorithm>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
#include <string>
#include <cmath>

using namespace std;

int main(){
    int K,S;
    int res = 0;

    cin >> K >> S;

    for (int x = 0; x <= K; x++){
        for (int y = x; y <= K; y++){
            for (int z = y; z <= K; z++){
                int total = x + y + z;
                if (total == S){
                    if (x == y && y == z){
                        res += 1;
                    } else if (x == y || y == z || z == x){
                        res += 3;
                    } else {
                        res += 6;
                    }
                }
            }
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 256
import math
N, M = map(int, input().split())
ans = 0
Nlist = list(map(int, input().split()))
total = sum(Nlist)
Mmin = math.ceil(total*1/(4*M))
ans = len([1 for x in Nlist if x >= Mmin])
if ans >= M:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9164
# -*- coding: utf-8 -*-
n, a, b, c, d = map(int, input().split())
s = input()
grid = []
for rock in s:
    grid.append(rock == '#')

if grid[c-1] or grid[d-1]:
    print('No')

max_rock_count = 0
rock_count = 0
if c < d:
    for i in range(a-1, d):
        if grid[i]:
            rock_count += 1
        else:
            rock_count = 0

        max_rock_count = max(max_rock_count, rock_count)

    if max_rock_count >= 2:
        print('No')
    else:
        print('Yes')
elif c > d:
    max_rock_count = 0
    rock_count = 0
    canSkip = False
    for i in range(a-1, c):
        if grid[i]:
            rock_count += 1
        else:
            if b - 1 <= i and i <= c - 2 and not grid[i-1] and not grid[i] and not grid[i+1]:
                if i-1 != d - 1:
                    canSkip = True
            rock_count = 0

        max_rock_count = max(max_rock_count, rock_count)

    if max_rock_count <= 1 and canSkip:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 5016
a,b,c,d=map(int,input().split())

flag=True
while a>0 and c>0:
   if flag:
      c-=b
      flag = not flag
      continue
   if not flag:
      a-=d
      flag = not flag
      continue
if a<=0:
   print('No')
else:
   print('Yes')

Measured memory_bytes: 61596