akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <complex>
#include <regex>
#include <random>
using namespace std;

#define rep(i,n)	for(lint i = 0; i < n; i++)
#define repr(i,n)	for(lint i = n - 1; i >= 0; i--)
#define repi(i,ini,n)	for(lint i = ini; i < n; i++)
#define repir(i,ini,n)	for(lint i = n-1; i >= ini; i--)
#define repb(i,start,end)	for(lint i = start; i <= end; i++)
#define repbr(i,start,end)	for(lint i = end; i >= start; i--)

#define bit(n)				(1LL << (n))

#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define rg(v, ini, end) v.begin() + ini, v.begin()+end

#define ret return 0;
#define chmax(a, b) a=mmax(a,b)
#define chmin(a, b) a=mmin(a,b)

using lint = long long;
using ulint = unsigned long long;
using ld = long double;
struct xy
{
	lint x, y;
	xy() :x(0), y(0) {}
	xy(lint _x, lint _y) : x(_x), y(_y) {}
	xy operator+(const xy& p) const
	{
		return xy(x + p.x, y + p.y);
	}
	bool operator<(xy p) const
	{
		if (y == p.y)
			return x < p.x;
		return y < p.y;
	}
};
struct xyd
{
	ld x, y;
	xyd() :x(0), y(0) {}
	xyd(long double _x, long double _y) : x(_x), y(_y) {}
};
using vec = vector<lint>;
using vecd = vector<ld>;
using vecs = vector<string>;
using vecp = vector<xy>;
template<class T> using vect = vector<T>;
class vec2 : public vector<vector<lint>>
{
public:
	vec2() {}
	vec2(lint n) : vector(n) {}
	vec2(lint h, lint w) : vector(h, vector<lint>(w)) {}
	vec2(lint h, lint w, lint v) : vector(h, vector<lint>(w, v)) {}
};

template<class T> using priq = priority_queue<T>;
template<class T> using rpriq = priority_queue<T, vector<T>, greater<T>>;
template<class Key, class Val> using hashmap = unordered_map<Key, Val>;
template<class Key> using hashset = unordered_set<Key>;

mt19937 mtrand((random_device())());

const double pi = 3.141592653589793238462;
const lint intmax = 9223372036854775807;
const lint inf = 1100100100100100100LL;

constexpr lint div2(lint p, lint q)
{
	return (p + q - 1) / q;
}

#if(__cplusplus < 201703L)

	lint gcd(lint a, lint b) {
		while (1) {
			if (a < b) swap(a, b);
			if (!b) break;
			a %= b;
		}
		return a;
	}

	lint lcm(lint a, lint b)
	{
		return a / gcd(a, b) * b;
	}

#endif

template<class T>
struct nval {
	lint n;		// counts
	T val;
	nval() : n(0) {};
	nval(lint _n, T _val) : n(_n), val(_val) {};
};

template<class It, class It2>
auto spacel(It i, It2 end)
{
	if (i + 1 == end)
	{
		return '\n';
	}
	else
	{
		return ' ';
	}
}

ostream& setp(ostream& ost)
{
	cout << setprecision(60) << fixed;
	return ost;
}

const ulint mod = 1000000007;
//const ulint mod = 998244353;
const ld eps = 0.0000001;


int main()
{
	lint a, b, c;
	cin >> a >> b >> c;

	lint k = 0;
	repb(i, a, b)
		if (c % i == 0)
			k++;

	cout << k << endl;
	return 0;
}



Measured memory_bytes: 3216
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int K = int.Parse(Console.ReadLine());
            string S = Console.ReadLine();

            if (K >= S.Length)
            {
                Console.WriteLine(S);
                return;
            }
            else
            {
                string cutS = S.Substring(0, K);
                Console.WriteLine(cutS + "...");
            }

        }
    }
}


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


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
 
    string s;
    cin>>s;
    int k;
    cin>>k;
    int n = s.size();
    ll dp[n+1][k+1][2]={};
    dp[0][0][0]=1;
    for(int i=0;i<n;i++){
        for(int j=0;j<=k;j++){
            dp[i+1][j][1] += dp[i][j][1];
            if(s[i]=='0') dp[i+1][j][0] += dp[i][j][0];
            if(s[i]!='0') dp[i+1][j][1] += dp[i][j][0];
            for(int h=1;h<=9;h++){
                if(j+1<=k && s[i]==('0'+h)) dp[i+1][j+1][0] += dp[i][j][0];
                if(j+1<=k){
                    dp[i+1][j+1][1] += dp[i][j][1];
                    if('0'+h < s[i]) dp[i+1][j+1][1] += dp[i][j][0];
                }
            }
        }
    }
    ll ans = dp[n][k][0] + dp[n][k][1];
    cout << ans << endl;


}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
flag=True
s=False
e=0
c=1
for i in range(1,n):
    if a[i]==a[i-1]:
        continue
    if a[i]>a[i-1]:
        flag=True
        e=i
        break
    elif a[i]<a[i-1]:
        flag=False
        e=i
        break
if e==n:
    print(1)
    exit()

for i in range(e+1,n):
    if a[i]==a[i-1]:
        continue
    if s==True:
        if a[i]>a[i-1]:
            s=False
            flag=True
        else:
            s=False
            flag=False
    elif a[i]>a[i-1] and flag==False:
        c+=1
        s=True
    elif a[i]<a[i-1] and flag==True:
        c+=1
        s=True
print(c)

Measured memory_bytes: 62704
#include <stdio.h>
int T[]={0,1867,1911,1925,1988};
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	if(a==0){
		if(b>1988)printf("H%d\n",b-1988);
		else if(b>1925)printf("S%d\n",b-1925);
		else if(b>1911)printf("T%d\n",b-1911);
		else printf("M%d\n",b-1867);
	}else{
		printf("%d\n",T[a]+b);
	}
}

Measured memory_bytes: 2716
#include<stdio.h>
int main(){
	int n,k,in[3][3],out[3][3],i,j;
	for(i=0;i<3;i++){
		for(j=0;j<3;j++)scanf("%d",&in[i][j]);
		for(j=0;j<3;j++)scanf("%d",&out[i][j]);
		for(j=0;j<3;j++)out[i][j]-=in[i][j];
		if(out[i][2]<0)--out[i][1],out[i][2]+=60;
		if(out[i][1]<0)--out[i][0],out[i][1]+=60;
		printf("%d %d %d\n",out[i][0],out[i][1],out[i][2]);
	}
	return 0;
}


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

namespace ABC129A
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] PQR = CIN.IntArray();
            Console.WriteLine(PQR.Sum() - PQR.Max());
        }
    }

    internal static class CIN
    {
        public static string String()
        {
            return Console.ReadLine();
        }

        public static int Int()
        {
            return int.Parse(Console.ReadLine());
        }

        public static int[] IntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }

        public static long Long()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] LongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] DoubleArray()
        {
            return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
        }
    }
}

Measured memory_bytes: 13396
#include<stdio.h>
int main(){
  int n,a[100],b[100],c[100],s=0,i;
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&a[i]);
  for(i=0;i<n;i++)scanf("%d",&b[i]);
  for(i=1;i<n;i++)scanf("%d",&c[i]);
  for(i=0;i<n;i++){
    s+=b[a[i]-1];//printf("%d ",s);
    if(i&&a[i-1]+1==a[i])s+=c[a[i-1]];//printf("%d\n",s);
  }
  printf("%d\n",s);
  return 0;
}


Measured memory_bytes: 128
import java.util.*;


public class Main {


	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ


		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int Q = sc.nextInt();
		String S = sc.next();
		int[] count = new int[N];
		Arrays.fill(count,0);
		for(int i = 1;i<N;i++) {
			if(S.charAt(i-1)=='A'&&S.charAt(i)=='C') {
				count[i] = count[i-1]+1;
			}else {
				count[i] = count[i-1];
			}
		}
		
		for(int i =0;i<Q;i++) {
			int l = sc.nextInt()-1;
			int r = sc.nextInt()-1;
			System.out.println(count[r]-count[l]);
		}
	}
}

Measured memory_bytes: 69592
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

class Main{
	public static void main(String[] args)throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(isr);
		Main app = new Main();
		String string;
		
		int pai[], tmp[];
		char data[];
		while((string = reader.readLine()) != null){
			data = string.toCharArray();
			pai = new int[10];
			tmp = new int[10];
			for(int i = 0; i < 13; i++){
				pai[data[i] - '0']++;
			}
			
			ArrayList<Integer> res = new ArrayList<Integer>();
			for(int i = 1; i < 10; i++){
				if(pai[i] < 4){
					pai[i]++;
					for(int j = 0; j < 10; j++) tmp[j] = pai[j];
					if(app.solve(tmp, 1, 0)){
						res.add(i);
					}
					pai[i]--;
				}
			}
			
			if(res.size() == 0) System.out.println(0);
			else{
				for(int i = 0; i < res.size(); i++){
					if(i == res.size() - 1){
						System.out.println(res.get(i));
					}else{
						System.out.print(res.get(i) + " ");
					}
				}
			}
		}
		reader.close();
	}
	
	public boolean solve(int pai[], int n, int f){
		boolean judge = false;
		if(f == 4){
			for(int var : pai){
				if(var == 2) return true;
			}
			return false;
		}
		if(pai[n] >= 3){
			pai[n] -= 3;
			judge = solve(pai, n, f + 1);
			if(judge) return true;
			pai[n] += 3;
		}
		if(n <= 7 && pai[n] >= 1 && pai[n + 1] >= 1 && pai[n + 2] >= 1){
			pai[n]--;
			pai[n + 1]--;
			pai[n + 2]--;
			judge = solve(pai, n, f + 1);
			if(judge) return true;
			pai[n]++;
			pai[n + 1]++;
			pai[n + 2]++;
		}
		if(n < 9) judge = solve(pai, n + 1, f);
		
		return judge;
	}
}

Measured memory_bytes: 24224
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s;
    int n;
    cin >> s;
    n = s.length();
    int ans0 = 0, ans1 = 0;

    for(int i = 0; i < n; i++) {
        if(i % 2 == 0) {
            if(s[i] == '1') {
                ans0++;
            } else {
                ans1++;
            }
        } else {
            if(s[i] == '1') {
                ans1++;
            } else {
                ans0++;
            }
        }
    }
    if(ans0 < ans1) {
        cout << ans0 << endl;
    } else {
        cout << ans1 << endl;
    }

    return 0;
}


Measured memory_bytes: 512
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, math.MaxInt64)
}

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

func main() {
	s := readString()
	fmt.Printf("%c%v%c\n", s[0], len(s)-2, s[len(s)-1])
}


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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define ALLTRUE(xs) all_of(ALL(xs),[](bool x){return x;})
#define AND(x,y,z) set_intersection((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define ANYTRUE(xs) any_of(ALL(xs),[](bool x){return x;})
#define CONCAT(x,y) (x).insert((x).end(),(y).begin(),(y).end())
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i)
#define OR(x,y,z) set_union((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)

typedef long long ll;
typedef pair<ll, ll> P;

struct edge { int to,cost; };

int main() {
  ll N,K;cin>>N>>K;
  map<int,ll> mp;
  REP(i,N) {
    int a,b;cin>>a>>b;
    mp[a] += b;
  }

  ll tmp = 0;
  for (auto m:mp) {
    if (tmp+m.second>=K) {
      OUT(m.first);
      break;
    }
    tmp += m.second;
  }

  return 0;
}

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

const int MAX = 210000;
const int MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

void init_ncr() {
    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 ncr(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(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  init_ncr();

  ll h,w,a,b;cin>>h>>w>>a>>b;
  ll ans = 0;
  for(ll i=0;i<w-b;i++){
    ans += ncr(b + i + h - a - 1, b + i) * ncr(a - 1 + w - b - 1 - i, a - 1) % MOD;
    ans %= MOD;
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 5120
#include<bits/stdc++.h>
#define ll long long int
#define endl '\n'
#define M 1000000007
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define f first
#define s second
#define b begin
#define e end
#define pb push_back
#define mp make_pair
#define FOR(i,a,b) for(i=a;i<b;i++)
#define RFOR(i,a,b) for(i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define itfr(it,x) for(it=x.begin();it!=x.end();it++)
#define flash ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;

int main()
{
    flash;
    //sieve();
    ll T=1,t,n,m,q,k,i,j;
    // cin>>T;
    while(T--)
    {
        cin>>n>>q;
        q = q*q;
        ll cnt=0;
        FOR(i,0,n)
        {
          cin>>m>>k;
          j = (m*m) + (k*k);
          if(j<=q)
            cnt++;
        }
        cout<<cnt<<endl;
    }
}

Measured memory_bytes: 3652
#include <stdio.h>
int min(int n,int m){
    if(n<m) return n;
    else return m;
}
int main(void){
    int p,q,r;
    scanf("%d%d%d",&p,&q,&r);
    printf("%d",min(min(p+q,p+r),q+r));
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <list>
#include <deque>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
#define dump(a) cout << (a) << endl;
typedef long long ll;
ll mod = 1e9+7;

int n;
vector<pair<int, ll>> edge[100001];
bool node[100001];
int q, k;

void dfs( int x, ll cost, ll d[] ) {
    if( node[x] ) return;
    node[x] = true;
    d[x] = cost;
    for( int i = 0; i < (int)edge[x].size(); i++ ) dfs( edge[x][i].first, cost+edge[x][i].second, d );
}

int main() {
    cin >> n;
    for( int i = 0; i < n-1; i++ ) {
        int a, b, c;
        cin >> a >> b >> c;
        edge[a].push_back( make_pair( b, c ) );
        edge[b].push_back( make_pair( a, c ) );
    }
    for( int i = 1; i <= n; i++ ) node[i] = false;
    cin >> q >> k;
    ll d[100001] = {};
    dfs( k, 0 , d);
    for( int i = 0; i < q; i++ ) {
        int a, b;
        cin >> a >> b;
        dump( d[a]+d[b] );
    }
    return 0;  
}

Measured memory_bytes: 16000
#include<stdio.h>
#define MIN(a,b) ((a)>(b)?(b):(a))
int main(){
  long long q,h,s,d,n;
  scanf("%lld%lld%lld%lld%lld",&q,&h,&s,&d,&n);
  s=MIN(s,MIN(h*2,q*4));
  d=MIN(d,s*2);
  printf("%lld",(n/2)*d+(n%2)*s);
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int gcd(int a, int b)
{
    if(b == 0)
        return a;
    return gcd(b, a % b);
}
int lcm(int a, int b)
{
    return (a * b) / gcd(a, b);
}
int main()
{
    int i,sum, n, mul;
    cin >> n;
    int ar[n+2];

    for(i = 0; i < n; i++)
        cin >> ar[i];
    sum  = 0;
    mul = 1;
    
    int lc = lcm(ar[0], ar[1]);
    for(i = 1; i < n; i++)
    {
        lc = lcm(lc, ar[i]);
    }
    for(i = 0; i < n; i++)
    {
        sum += lc/ar[i];
    }
    double result = (double)lc / sum;

    cout << result<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
int main()
{
	int n;
	cin >> n;
	vector<int> b(n);
	for(int i=0;i<n-1;i++)
	{
		cin >> b[i];
	}
	if(n==2)
	{
		cout << b[0]*2;
		return 0;
	}
	int sum=0;
	sum+=b[0];
	sum+=min(b[0],b[1]);
	for(int i=1;i<n-1;i++)
	{
		sum+=min(b[i],b[i+1]);
	}
	sum+=b[n-2];
	cout << sum;
	return 0;
}

Measured memory_bytes: 256
/*=====Bismillahir Rahmanir Rahim=====*\
!                                      !
!(^,^)Ron is back(-o,o-)               !
!         MD. TAREK MAHMUD RONY        !
!            CSE 12th Batch            !
!           Comilla University         !
\*====================================*/
//Think positive, be positive and never use negative words
#include<bits/stdc++.h>
#define ll               long long int
#define test             ll t;cin>>t;while(t--)
#define nl               endl
#define mp(a,b)          make_pair(a,b)
#define F                first
#define S                second
#define vc               vector<int>
#define vcl              vector<ll>
#define pb               push_back
#define vc_sum(a)        accumulate(a.begin(),a.end(),0)
#define vc_max(a)        *max_element(a.begin(),a.end())
#define vc_min(a)        *min_element(a.begin(),a.end())
#define vc_sort(a)       sort(a.begin(),a.end())
#define vc_gsort(a)      sort(a.begin(),a.end(),greater<int>())
#define vc_uni(a)        a.erase(unique(a.begin(),a.end()),a.end())
#define ulta(a)          reverse(a.begin(),a.end())
#define RON              ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define yes              cout<<"YES"<<nl
#define no               cout<<"NO"<<nl
#define M                1000000007
#define gcd(a,b)         __gcd(a,b)
#define lcm(a,b)         (a/gcd(a,b))*b
using namespace std;
int main()
{
    RON;
    ll a;
    cin>>a;
    cout<<a+(a*a)+(a*a*a)<<nl;
    return 0;
}



Measured memory_bytes: 3604
//WA

#include<stdio.h>
#include<string.h>
int main()
{
    char a[110]={};
    int n,i,j,leap=0;
    while(~scanf("%s",a))
    {
        n=strlen(a);
        for(j=n-1,i=0;i<n/2;j--,i++)
        {
//            printf("one:%d %c-%d %c\n",i,a[i],j,a[j]);
            if(a[i]!=a[j])
            {
                leap=1;
                break;
            }
        }
        if(leap)
            printf("No\n");
        else
        {
            for(i=0,j=(n-1)/2-1;i<(n-1)/4;j--,i++)
            {
//                printf("two:%d %c-%d %c\n",i,a[i],j,a[j]);
                if(a[i]!=a[j])
                {
                    leap=1;
                    break;
                }
            }
            if(leap)
                printf("No\n");
            else
            {
                for(i=(n+3)/2-1,j=n-1;i<n;i++,j--)
                {
//                    printf("three:%d %c-%d %c\n",i,a[i],j,a[j]);
                    if(a[i]!=a[j])
                    {
                        leap=1;
                        break;
                    }
                }
                if(leap)
                    printf("No\n");
                else
                    printf("Yes\n");
            }
        }
        leap=0;
    }
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int h,w;
    cin>>h>>w;
    char c[26];
    for(char i='A';i<='Z';i++){
        c[i-'A']=i;
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            string a;
            cin>>a;
            if(a=="snuke"){
                cout<<c[j]<<i+1<<endl;
            }
        }
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
char s[999][999];
int main()
{
    int n,m,i,j;
    while(~scanf("%d %d",&n,&m))
    {
        getchar();
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=m;j++)
            {
                scanf("%c",&s[j][i]);
            }
            getchar();
        }
         for(i=1;i<=n;i++)
        {
            for(j=1;j<=m;j++)
            {
                printf("%c",s[j][i]);
            }
            printf("\n");
            for(j=1;j<=m;j++)
            {
                printf("%c",s[j][i]);
            }
            printf("\n");
        }
    }
    return 0;
}


Measured memory_bytes: 1740
class UnionFind:
    def __init__(self, n):
        self.parents = [-1] * n
 
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
 
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
 
        if x == y:
            return
 
        if self.parents[x] > self.parents[y]:
            x, y = y, x
 
        self.parents[x] += self.parents[y]
        self.parents[y] = x
 
    def is_same_root(self, x, y):
        return self.find(x) == self.find(y)
 
    def get_group_size(self, x):
        return -self.parents[self.find(x)]
    
    
n,m,k=map(int,input().split())
uf = UnionFind(n)

ans=[0  for i in range(n)]
for i in range(m):
    x,y=map(int,input().split())
    uf.union(x-1,y-1)
    ans[x-1]-=1
    ans[y-1]-=1
    
for i in range(k):
    x,y=map(int,input().split())
    if uf.is_same_root(x-1,y-1):
        ans[x-1]-=1
        ans[y-1]-=1

for i in range(n):
    ans[i]+=uf.get_group_size(i)-1
print(*ans)

Measured memory_bytes: 13364
let n = stdin.ReadLine() |> int
let p = stdin.ReadLine().Split() |> Array.map int |> Array.toList

let rec f ls min cnt =
 match ls with
 | [] -> cnt
 | hd :: tl -> if (hd < min) then f tl hd (cnt + 1)
               else f tl min cnt

f p (n + 1) 0
|>stdout.WriteLine

Measured memory_bytes: 37340
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
const int maxn=2001;
const int maxk=10009;
int n,K,len[maxn];
char s[maxn][maxk];
bitset<maxk> bit[maxn];
pii v[2][maxk];
int main()
{
    scanf("%d%d",&n,&K);
    for (int i=1;i<=n;++i) {
        scanf("%s",s[i]);
        len[i]=strlen(s[i]);
    }
    bit[n+1][0]=1;
    for (int i=n;i>=1;--i)
        bit[i]=bit[i+1]|(bit[i+1]<<len[i]);
    int c1=0;
    for (int i=1;i<=n;++i)
        if (bit[i+1][K-len[i]])
            v[1][++c1]=pii(i,0);
    for (int o=1;o<=K;++o) {
        char mmin='z';int c2=0;
        for (int i=1;i<=c1;++i)
            mmin=min(mmin,s[v[o&1][i].first][v[o&1][i].second]);
        putchar(mmin);
        int ID=n+1;
        for (int i=1;i<=c1;++i) {
            int id=v[o&1][i].first,pos=v[o&1][i].second;
            char ch=s[id][pos];
            if (ch!=mmin) continue;
            if (pos+1==len[id]) ID=min(ID,id);
            else v[(o+1)&1][++c2]=pii(id,pos+1);
        }
        for (int i=ID+1;i<=n;++i)
            if (K-o-len[i]>=0&&bit[i+1][K-o-len[i]])
                v[(o+1)&1][++c2]=pii(i,0);
        c1=c2;
    }
    return 0;
}


Measured memory_bytes: 15112
#include<iostream>
#include <algorithm>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <vector>
using namespace std; 
const int Nmax = 10000;
const int INF = 1000000000;
const int MOD = 1000000007;

int main()
{   
	long long  int n;
	long long sum=0;
	long long  in_sum=0;
	cin>>n;
	vector<long long unsigned> arr(100005,0);
	for(long long  i=0;i<n;i++){
		long long  x;
		cin>>x;
		arr[x]++;
		in_sum+=x;
	}
	long long  q;
	cin>>q;
	while(q--){
		long long  b,c;
		cin>>b>>c;
		in_sum-=b*arr[b];
		in_sum+=c*arr[b];
		arr[c]+=arr[b];
		arr[b]=0;
		
		cout<<in_sum<<endl;
	}
    return 0;
}

Measured memory_bytes: 4044
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()
 
#define REP(i,s,e)	for(int i=(s); i<(e); i++)
#define rep(i,n)	REP(i,0,n)
#define REPE(i,s,e)	for(int i=s; i>e; i--)
#define repe(i,n)	REPE(i,n,-1)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<vi> vii;
 
const int IMAX=((1<<30)-1)*2+1;
const int INF=100000000;
const double EPS=1e-10;
//int mod=1000000007
 

 



int main(){
	for(int i=1; i<10; i++){
		for(int j=1; j<10; j++){
			cout<<i<<"x"<<j<<"="<<i*j<<endl;
		}
	}
}

Measured memory_bytes: 1116
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,tmp;
	scanf("%d %d %d",&a,&b,&c);
	if(a>b)
	{
		tmp=a;
		a=b;
		b=tmp;
	}
	if(a>c)
	{
		tmp=a;
		a=c;
		c=tmp;
	}
	if(c<b)
	{
		tmp=c;
		c=b;
		b=tmp;
	}
	printf("%d",b-a+c-b);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <deque>
#include <iomanip>


using namespace std;


typedef long long ll;


int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cerr.tie(0);

  int N, K;
  string s;

  cin >> N >> K >> s;

  vector<int> conZeros;
  vector<int> conOnes;
  char prevSeen = '1';
  int run = 0;
  for (int i = 0 ; i < N ; i++) {
    if (prevSeen == s[i]) {
      run++;
    } else {
      if (prevSeen == '0') {
       conZeros.push_back(run);   
       run = 1;
       prevSeen = '1';
      } else {
       conOnes.push_back(run);   
       run = 1;
       prevSeen = '0';
      }
    }
  }
  
  if (prevSeen == '0') {
      conZeros.push_back(run);
      conOnes.push_back(0);
  } else {
    conOnes.push_back(run);
  }
/*
  for (int x : conZeros) {
    cout << x << " ";
  }
  cout << "\n";
  for (int x : conOnes) {
    cout << x << " ";
  }
  cout << "\n";
*/
  K = min(K, (int)conZeros.size());
  int sum = 0, ans = 0;
  for (int i = 0 ; i <= K-1 ; i++) {
    sum += conZeros[i];
    sum += conOnes[i];
  }
  sum += conOnes[K];
  ans = max(ans, sum);
  for (int i = 1 ; i+K-1 < conZeros.size() ; i++) {
    sum -= conZeros[i-1];
    sum -= conOnes[i-1];
    sum += conZeros[i+K-1];
    sum += conOnes[i+K];

    ans = max(ans, sum);
  }


  cout << ans;


  return 0;
}




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

int main()
{
  int n;
  double t,a;
  cin >> n >> t >> a;
  int h[n];
  int i;
  for(i = 0;i < n;i++){
    cin >> h[i];
  }
  double sa[n];
  int ans = 0;
  for(i = 0;i < n;i++){
    sa[i] = a -(t - 0.006*h[i]);
    if(sa[i] < 0){
    sa[i] = -sa[i];
    }
  }
  for(i = 0;i < n;i++){
    if(sa[ans] > sa[i]){
      ans = i;
    }
  }
  ans++;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#![allow(non_snake_case)]

use std::io::*;

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

pub fn main() {
    let S = rl().chars().collect::<Vec<char>>();

    let ok = S[0] == 'A'
        && S.last().unwrap().is_lowercase()
        && S[2..S.len() - 1].iter().filter(|&&c| c == 'C').count() == 1
        && S[1..].iter().filter(|&&c| !c.is_lowercase()).count() == 1;
    println!("{}", if ok { "AC" } else { "WA" })
}


Measured memory_bytes: 4352
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
#include <numeric>
#include <random>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef vector<pair<int, int> > VPII;
typedef vector<string> VS;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<int, int> P;
typedef pair<int, pair<P, P> > PP;

#define INF 999999999999999997;
#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORL(i,a,b) for(LL i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
#define O(s) cout<<s<<endl;

#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}

template<class T>T IN() { T d; cin >> d; return d; }

LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; } // 最大公約数（Greatest Common Divisor）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; } // 最小公倍数（Least Common Multiple）
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); } // うるう年判定

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int dxx[8] = { 0,1,1,1,0,-1,-1,-1 };
int dyy[8] = { 1,1,0,-1,-1,-1,0,1 };

// vector注意
// vec[i][j]の形に入力を入れるとき、vecは初期化してある必要がある.

// ------------------- include, typedef, define END. -------------------

int main() {
	FAST_IO;
	bool dbgF = true; // for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;

	LL N;
	VL A;
	cin >> N;
	FOR(i, 0, N)
		A.push_back(IN<LL>());

	// 全パターン数を求める
	LL ans = 1;
	FOR(i, 0, N) {
		// 積=0も偶数とする
		ans *= 3;
		// 積が0のときは偶数としない
		/*if (A[i] == 1) {
			ans *= 2;
		}
		else {
			ans *= 3;
		}*/
	}
	// 積が奇数のものを減らす
	LL kisuu = 1;
	FOR(i, 0, N) {
		if (A[i] % 2 == 0) {
			kisuu *= 2;
		}
		else {
			kisuu *= 1;
		}
	}
	O((ans - kisuu));

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
    string s;
    cin>>s;
    cout<<"ABC"<<s<<endl;
    return 0;
}

Measured memory_bytes: 256
MOD = 10**9+7
n = int(input())
A = list(map(int, input().split()))

colors = [0]*3
dp = [0]*n
for i in range(n):
    c = colors.count(A[i])
    dp[i] = c
    if c == 0:
        break
    colors[colors.index(A[i])] += 1

ans = 1
for x in dp:
    ans = ans*x % MOD
print(ans % MOD)


Measured memory_bytes: 14396
#include <vector>
#include <iostream>
using namespace std;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge> >;

Graph G;
vector<int> d;
void Dfs(int v, int parent, int color = 0)
{
    d[v] = color; 
    for (auto e : G[v])
    {
        if (e.first == parent) continue; // 逆流を防ぐ(探索の肝！)
        if (e.second & 1) Dfs(e.first, v, 1-color);
        else Dfs(e.first, v, color);
    }
}

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

    int u, v, w;
 
    G.assign(N, vector<Edge>());
    for (int i = 0; i < N - 1; ++i)
    {
        cin >> u >> v >> w;
        --u; --v;
        G[u].push_back(Edge(v, w));
        G[v].push_back(Edge(u, w));
    }

    d.assign(N, 0);
    Dfs(0, -1);
    for (auto ans : d) cout << ans <<endl;
    return 0;
};


Measured memory_bytes: 8960
from collections import Counter
n=int(input())
l=[int(i) for i in input().split()]
sm=sum(l)
z=int(input())
c=Counter(l)
for i in range(z):
    a,b=map(int,input().split())
    sm-=c[a]*a
    sm+=c[a]*b
    c[b]+=c[a]
    c[a]=0
    print(sm)

Measured memory_bytes: 24028
from heapq import heappush, heappop

# 入力
N = int(input())
u, v, w = (
    zip(*(map(int, input().split()) for _ in range(N - 1))) if (N - 1) else
    ((), (), ())
)

# 頂点1からの距離が偶数である頂点は白、奇数である頂点は黒で塗る
G = [{} for _ in range(N + 1)]
for x, y, c in zip(u, v, w):
    G[x][y] = c
    G[y][x] = c
INF = 10**18


def dijkstra(G, s):
    dp = [INF for _ in range(len(G))]
    q = []
    heappush(q, (0, s))
    while q:
        c, i = heappop(q)
        if dp[i] == INF:
            dp[i] = c
            for j, w in G[i].items():
                heappush(q, (c + w, j))
    return dp


dp = dijkstra(G, 1)
ans = '\n'.join(
    str(dp[i] % 2)
    for i in range(1, N + 1)
)

# 出力
print(ans)


Measured memory_bytes: 67928
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
import itertools

def main():
    n, m = map(int , input().split())
    a = len(list(itertools.combinations(list(range(n)), 2)))
    a += len(list(itertools.combinations(list(range(m)), 2)))
    print(a)


if __name__=="__main__":
    main()


Measured memory_bytes: 64248
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        int[] h = new int[n];
        for(int i = 0; i < n; i++){
            h[i] = Integer.parseInt(sc.next());
        }
        Arrays.sort(h);
        
        int min = 1000000000;
        int x;
        for(int i = 0; i+k-1 < n; i++){
            x = h[i+k-1] - h[i];
            if(x < min){
                min = x;
            }
        }
        
        System.out.println(min);
    }
}

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

int W[100005], V[100005];
long long dp[2][100005];

int main() {

    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
    
    int N, w;
    cin >> N >> w;
    
    for(int i=1; i<=N; i++)
        cin >> W[i] >> V[i];
    
    int prev = 0, curr = 1;
    
    for(int i=1; i<=N; i++, swap(prev, curr))
    {
        for(int j=0; j<=w; j++)
        {
            dp[curr][j] = dp[prev][j];
            
            if(i >= 1 && j >= W[i])
                dp[curr][j] = max(dp[curr][j], dp[prev][j - W[i] ] + V[i]);
        }
    }
    
    cout << dp[prev][w] << "\n";
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
 
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

template<class D>
struct Hungarian {
    V<D> le, ri;
    V<int> perm;

    Hungarian(const VV<D> &c) {
        int n = int(c.size()), m = int(c[0].size());
        assert(n <= m);
        le = V<D>(n, D(0)); ri = V<D>(m, D(0));
        perm = V<int>(n);
        V<int> to_r(n, -1), to_l(m, -1);

        auto cost = [&](int l, int r) { return c[l][r] + le[l] + ri[r]; };
        for (int l = 0; l < n; l++) {
            V<bool> l_u(n), r_u(m);
            V<int> tr(m, -1), min_l(m, l);
            l_u[l] = true;
            V<D> cost_buf(m);
            for (int j = 0; j < m; j++) cost_buf[j] = cost(l, j);
            while (true) {
                int b = -1;
                D d = numeric_limits<D>::max();
                for (int j = 0; j < m; j++) {
                    if (!r_u[j] && cost_buf[j] < d) {
                        b = j;
                        d = cost_buf[j];
                    }
                }
                for (int i = 0; i < n; i++) if (l_u[i]) le[i] -= d;
                for (int j = 0; j < m; j++) {
                    if (r_u[j]) ri[j] += d;
                    else cost_buf[j] -= d;
                }
                tr[b] = min_l[b];
                int c = to_l[b];
                if (c == -1) {
                    while (b != -1) {
                        int a = tr[b], z = to_r[a];
                        to_l[b] = a;
                        to_r[a] = b;
                        b = z;
                    }
                    break;
                }
                l_u[c] = r_u[b] = true;
                for (int j = 0; j < m; j++) {
                    if (cost(c, j) < cost_buf[j]) {
                        min_l[j] = c;
                        cost_buf[j] = cost(c, j);
                    }
                }
            }
        }
        perm = to_r;
    }    
};

 
using D = double;
const D PI = acos(D(-1)), EPS = 1e-10;
using P = complex<D>;
 
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20) << fixed;
 
    D ans = 0;
 
    int n;
    cin >> n;
    V<P> up(n), dw(n);
    D x, y;
    cin >> x >> y;
    for (int i = 0; i < n; i++) {
        cin >> x >> y; up[i] = P(x, y);
        cin >> x >> y; dw[i] = P(x, y);
        ans += abs(up[i]-dw[i]);
    }
 
    int l = int(up.size()), r = int(dw.size());
    VV<D> cost(l, V<D>(r));
    for (int i = 0; i < l; i++) {
        for (int j = 0; j < r; j++) {
            cost[i][j] = abs(up[i] - dw[j]);
        }
    }
    auto perm = Hungarian<D>(cost).perm;
    for (int i = 0; i < l; i++) {
        ans += cost[i][perm[i]];
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3896
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <memory>
#include <string>

#include <algorithm>
#include <complex>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
#endif

#define ITER(c)         __typeof__((c).begin())
#define FOREACH(it, c)  for (ITER(c) it=(c).begin(); it != (c).end(); ++it)
#define RITER(c)        __typeof__((c).rbegin())
#define RFOREACH(it, c) for (RITER(c) it=(c).rbegin(); it != (c).rend(); ++it)
#define REP(i, n)       REPEAT(i, 0, n)
#define REPEAT(i, k, n) for (int i = (k); i < (n); ++i)
#define REVREP(i, n)    for (int i = ((n)-1); i >= 0; --i)
#define FIND(c, n)      std::find((c).begin(), (c).end(), (n));
#define BSEARCH(c, n)   std::binary_search((c).begin(), (c).end(), (n))
#define LLPOW(p1,p2)    ((ll)pow((double)(p1), (int)p2))
#define ESIZEOF(A)      (sizeof(A)/sizeof((A)[0]))
#define MIN(p1,p2)      (((p1)<(p2))?(p1):(p2))
#define MAX(p1,p2)      (((p1)>(p2))?(p1):(p2))
#define CIN_NO_SYNC     do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0)
#define GETSTR(p)       fgets((p), sizeof(p), stdin)
#define CHOMP(p)        do{ char *_q = (p) + strlen(p)-1; if(*_q == '\n') *_q = 0; } while(0)

int main(){
    string s;
    while(cin >> s, s != "0"){
        int sum = 0;
        REP(i, s.length()){
            sum += (s[i]-'0');
        }
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 1188
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<ll, int> P;
#define MOD (1000000007ll)
#define l_ength size

int main(void){
	int n,a,b,q,k,x,y,i;
	ll c,e,d[123456];
	P tmp;
	fill(d,d+123456,INFLL);
	vector<P> g[123456];
	priority_queue< P, vector<P>, greater<P> > pq;
	cin >> n;
	for(i=1; i<n; ++i){
		cin >> a >> b >> c;
		g[a].push_back(P(c,b));
		g[b].push_back(P(c,a));
	}
	cin >> q >> k;
	d[k] = 0ll;
	pq.push(P(d[k],k));
	while(!pq.empty()){
		tmp = pq.top();
		pq.pop();
		a = tmp.second;
		c = tmp.first;
		for(i=(g[a].size()-1); i>=0; --i){
			b = g[a][i].second;
			e = g[a][i].first;
			if(d[b] > c + e){
				d[b] = c + e;
				pq.push(P(d[b],b));
			}
		}
	}
	for(i=0; i<q; ++i){
		cin >> x >> y;
		cout << (d[x]+d[y]) << endl;
	}
	return 0;
}

Measured memory_bytes: 11888
#include <stdio.h>
#include <string.h>
int main(void){
    // Your code here!
    int i,j,n,h,len;
    char str[201],tmp[201];
    
    while(1){
        scanf("%s", &str);
        if(str[0]=='-') break;
        len=strlen(str);
        scanf("%d", &n);
        for(i=0;i<n;i++){
            scanf("%d", &h);
            for(j=0;j<len;j++) tmp[j]=str[j];
            for(j=0;j<len-h;j++){
                str[j]=str[j+h];
            }
            for(j=0;j<h;j++){
                str[j+len-h]=tmp[j];
            }
        }
        printf("%s\n",str);
    }
    return 0;
}



Measured memory_bytes: 2108
#pragma GCC optimize("Ofast")
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>
#include<queue>

using namespace std;

int main(){	
	string s;
	cin >> s;
	int cnt=0;
	for(int i=0;i<s.size();i++){
		cnt+=(s[i]-'0');
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 3564
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def read_a_int(): return int(read())


def read_ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from math import gcd
# 文字の順番を扱うとき


def ord_from_a(char):
    return ord(char) - ord('a')


def chr_from_a(n: int):
    # nはaから何番あとかを示す
    if n == -1:
        n = 25
    return chr(n + ord('a'))


N = read_a_int()
# 文字列の桁数nの決定
num = 0
for i in range(1, 100):
    num += 26**i
    if N <= num:
        break  # 桁数の決定
n = i
N -= (26 ** n - 1) // 25

ans = ''
for i in range(n):
    N, r = divmod(N, 26)
    ans = chr_from_a(r) + ans


print(ans)


Measured memory_bytes: 86928
n, m = map(int, input().split())
a = [-1] + [int(input()) for i in range(m)] + [n+1]

res = 1
for i in range(1, len(a)):
    if a[i] == 1:
        continue
    tmp = a[i] - a[i-1] - 2
    if tmp < 0:
        tmp2 = 0
    elif tmp <= 1:
        tmp2 = 1
    elif tmp <= 2:
        tmp2 = 2
    else:
        p, q = 2, 1
        for j in range(1, tmp-1):
            p, q = p+q, p
        tmp2 = p
    res *= tmp2
    res %= 1000000007

print(res)


Measured memory_bytes: 7824
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int N,K;
int S[101];

int main(){
  while(1){
    scanf("%d %d",&N,&K);
    if(!N && !K) break;
    for(int i=0;i<K;i++){
      scanf("%d",&S[i]);
    }
    bool f = false;
    for(int i=0;i<N;i++){
      for(int j=0;j<K;j++){
	int b;
	scanf("%d",&b);
	S[j]-=b;
	if(S[j]<0) f=true;
      }
    }
    if(f) printf("No\n");
    else printf("Yes\n");
  }
}

Measured memory_bytes: 1168
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

int main() {
  int N, M;
  while(cin >>N >>M && (N || M)){
    vector<int> v(N + M + 1);
    REP(i, N) cin >>v[i];
    REP(i, M) cin >>v[i + N];
    v[N + M] = 0;
    SORT(v);
    int ans = 0;
    FOR(i, 1, N + M + 1) ans = max(ans, v[i] - v[i - 1]);
    cout <<ans <<endl;
  }
  return 0;
}

Measured memory_bytes: 1292
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int n, k; readV(n, k);
  writeln(n == k ? 1 : (n-2)/(k-1)+1);
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<ll,ll> > vpll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vll> vvll;
typedef map<int,int> mii;
typedef set<int> si;
#define rep(i,n) for(ll i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define arep(i,v) for(auto i : v)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define fi first
#define se second
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
template <class T> inline void dump(T &v){irep(i, v){cout<<*i<<((i==--v.end())?'\n':' ');}}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
constexpr ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-11;

int solve(vi &v, ll P, int n, int k) {
    int need = 0;
    int sum=0;
    for(int i=0;i<n;i++){
        if(v[i]>P)return 0;
        else if(sum+v[i]>P){
            need++;
            sum=v[i];
        } else {
            sum+=v[i];
        }
    }
    if(sum>0)need++;
    return (need <= k);
}
int main() {
    
    int n,k;
    cin>>n>>k;
    vi v(n);
    rep(i,n)cin>>v[i];
    
    int ng = -1; //これがx以下 
    ll ok = 1e15; //x以上 
    // 問題によってokとngを入れ替える
    while(abs(ok - ng) > 1){
        int mid = (ok + ng)/2;
        if(solve(v,mid,n,k)) ok = mid;
        else ng = mid;
    }
    cout<< ok<<endl;
}


Measured memory_bytes: 3116