akhauriyash/Code-Regression huggingface dataset:
import numpy as np
def f(nums, a):
  return 0  if nums.size<=1 else (np.searchsorted(nums, a//nums, side='right').sum()-np.searchsorted(nums, int(pow(a, 1/2)), side='right'))//2

N, K=map(int, input().split())
A=np.sort(list(map(int, input().split())))

p=np.sum(A>0)
q=np.sum(A<0)
Z=N-p-q
AP=A[-p:] if p>0 else np.array([])
AN=A[:q] if q>0 else np.array([])

b=(N-Z)*Z+Z*(Z-1)//2
a=p*q

if K<=a:
  x=AP[-1]*AN[0]-1
  y=AP[0]*AN[-1]
  while y-x>1:
    tmp=(y+x)//2
    counter=np.searchsorted(AN, tmp//AP, side='right').sum()
    if counter<K:
      x=tmp
    else:
      y=tmp
  print(y)
elif K<=a+b:
  print(0)
else:
  if q>1:
    AN=-AN[::-1]
  x=0
  y=10**18
  K=K-a-b
  while y-x>1:
    tmp=(y+x)//2
    if f(AP, tmp)+f(AN, tmp)<K:
      x=tmp
    else:
      y=tmp
  print(y)

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> a(n+1);
  long long ans = 0;
  for ( int i = 1, s = -1; i <= n; ++ i) {
    cin >> a[i];
    ans += a[i] >> 1;
    if( !a[i]) {
      s = -1;
    }
    a[i] = a[i]&1;
    if( a[i] && ~ s) {
      ++ ans; s = -1;
    } else if( a[i]) {
      s = i;
    }
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 640
h,w=gets.split(" ").map(&:to_i)
a=Array.new(h,"")
for i in 0...h do
    a[i]=gets
end
puts "#"*w
for i in 1..h-2 do
    out=""
    for j in 0...w do
        if j%2==1||a[i][j]=="#" then
            out+="#"
        else
            out+="."
        end
    end
    puts out
end
puts "."*w
puts ""
puts "."*w
for i in 1..h-2 do
    out=""
    for j in 0...w do
        if j%2==0||a[i][j]=="#" then
            out+="#"
        else
            out+="."
        end
    end
    puts out
end
puts "#"*w

Measured memory_bytes: 4988
#include <iostream>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main(){
  int n, ct=0, i, ans=0;
  cin >> n;
  int a[n];
  for(i=0; i<n; i++)
    cin >> a[i];
  sort(a, a+n);
  for(i=0; i<n-1; i++){
    if(a[i]!=a[i+1]){ct++;
      if(ct>a[i]) ans+=(ct-a[i]);
      else if(ct<a[i]) ans+=ct;
      ct=0;
    }
    else{
      ct++;
    }
  }
  ct++;
   if(ct>a[n-1]) ans+=(ct-a[n-1]);
      else if(ct<a[i]) ans+=ct;
   cout << ans;
   return 0;
}

Measured memory_bytes: 640
use std::io::{stdin, Read};
use std::str::FromStr;

// https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[allow(dead_code)]
fn main() {
    let n = read::<usize>();
    let mut a = (0..n).map(|_| read::<i64>()).collect::<Vec<_>>();

    a.sort();
    let mut total = 0;
    for i in 0..n {
        total += a[i]
    }

    for i in 0..n / 2 {
        let candidate = total + a[2 * i] * (-1) * 2 + a[2 * i + 1] * (-1) * 2;
        if total < candidate {
            total = candidate
        } else {
            break;
        }
    }
    println!("{}", total)
}


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

int main() {
  int N,K;
  cin >> N >> K;
  string S;
  cin >> S;
  for (int i = 0; i < N; i++) {
    if (i == K - 1) {
      char a = S.at(i) + 32;
      cout << a;
    }
    else {
      cout << S.at(i);
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector> 
#include <cstring>
#include <queue>
#include <ctime>
#include <set>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const ll INF = 10e16;
const int maxN = 500010;
const int maxD = 15;
const int maxH = 100; 
const int MOD = 1000000007;

int a[maxN]; 
int main()
{
	ll n,x,y;
	scanf("%lld%lld%lld",&n,&x,&y);
	ll m = n/(x+y);
	ll ans = m * x;
	ll z = n%(x+y);
	z = min(z,x);
	ans += z;
	cout<<ans<<endl; 
	return 0;
}

Measured memory_bytes: 256
sl = [int(input()) for i in range(int(input()))]
smsl = sum(sl)
if smsl % 10 != 0:
  print(smsl)
else:
  non10 = [i for i in sl if i % 10 != 0]
  if not non10:
    print(0)
  else:
    print(smsl - min(non10))

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
    int n, pm, pe, pj;
    while(cin >> n, n){
	while(n--){
	    cin >> pm >> pe >> pj;
	    if(pm == 100 || pe == 100 || pj == 100){
		cout << "A" << endl;
		continue;
	    }
	    if(pm + pe >= 180){
		cout << "A" << endl;
		continue;
	    }
	    if(pm + pe + pj >= 240){
		cout << "A" << endl;
		continue;
	    }
	    if(pm + pe + pj >= 210){
		cout << "B" << endl;
		continue;
	    }
	    if(pm + pe + pj >= 150 && (pm >= 80 || pe >= 80)){
		cout << "B" << endl;
		continue;
	    }
	    cout << "C" << endl;
	}
    }
    return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
const int MAX = 1000001;
const int MOD = 1000000007;
   
        signed main() {
    cout<<fixed<<setprecision(10);
       int n;
       cin>>n;
        if((n/100)*111<n)cout<<(n/100+1)*111;
        else cout<< (n/100)*111;

        }


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <climits>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <tuple>
#define ll long long
using namespace std;
/*階乗*/
ll factorial(ll n){
    if(n==0){
        return 1;
    }
    else{
        return n*factorial(n-1);
    }
}

/* ユークリッドの互除法 最大公約数*/
/*ll gcd(ll a, ll b) {
	ll r;
	r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}
*/


/*最小公倍数*/
/*
ll lcm(ll a,ll b){
	return a/gcd(a,b)*b;
}
*/

/*二点間の距離*/
double dist(pair<double,double> a,pair<double,double> b){
	return sqrt(pow((a.first - b.first) ,2) + pow((a.second - b.second),2));
}

//繰り返し自乗法
double ism(double aa,ll p){
    double ap=aa;
    double ans=1;
    while(p>0){
        //cout<<"p="<<p<<",ap="<<ap<<endl;
        if(p&1){//奇数が真
            ans*=ap;
        }
        p/=2;
        ap=ap*ap;
    }
    return ans;

}
//繰り返し自乗法(アマリトリバージョン)
ll ismm(ll aa,ll p,ll m){
    ll ap=aa;
    ll ans=1;
    while(p>0){
        //cout<<"p="<<p<<",ap="<<ap<<endl;
        if(p&1){//奇数が真
            ans=(ans*ap)%m;    
        }
        p/=2;              
        ap=(ap*ap)%m;
    }
    return ans;

}
/*
ll solve(ll i,ll m,vector<ll>t,ll n){
    if(m==0){
        return 1;
    }
    if(i>=n){
        return 0;
    }
    
    
    cout<<i+1<<" "<<m<<endl;
    cout<<i+1<<" "<<m-t[i]<<endl;
    ll res=solve(i+1,m,t,n)||solve(i+1,m-t[i],t,n);
    return res;
}
*/

//小数点12桁
struct all_init
{
    all_init()
    {
        cout << fixed << setprecision(12);
    }
} All_init;


int main()
{
    ll n,count=0,count2=0;
    cin>>n;
    vector<ll>a(n);
    for(ll i=0;i<n;i++){
        cin>>a[i];
    }
    for(ll i=0;i<n;i++){
        if(a[i]%2==0){
            count++;
        }
    }
    for(ll i=0;i<n;i++){
        if(a[i]%2==0&&(a[i]%3==0||a[i]%5==0)){
            count2++;
        }
    }
    if(count==count2){
        cout<<"APPROVED"<<endl;
    }
    else{
        cout<<"DENIED"<<endl;
    }


    

}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<map>
#include<random>
#include<functional>

#define rep(i,n) for(int i=0; i<n; i++)
#define pb push_back
#define pint pair<int, int>
#define mp make_pair

using namespace std;

typedef long long ll;


int N;
vector<pint> b;
bool co[100005] = {};

int main() {
	cin >> N;
	rep(i, N) {
		int a;
		cin >> a;
		b.push_back(mp(a, i + 1));
	}

	sort(b.begin(), b.end(), greater<pint>());

	int ret = 0, cnt = 0;
	rep(i, N) {
		if (b[i].first == 0) break;

		int tmp = b[i].second;
		
		co[tmp] = true;

		cnt++;
		if (co[tmp + 1]) cnt--;
		if (co[tmp - 1]) cnt--;

		if (i == N-1 || b[i].first != b[i + 1].first) {
			ret = max(ret, cnt);
		}
	}

	cout << ret << endl;


	return 0;
}




Measured memory_bytes: 3900
L=[]
i=0
while i <100001:
    L.append(0)
    i+=1
for x0 in range(1,100):
    for y0 in range(1,100):
        for z0 in range(1,100):
            p=x0**2+y0**2+z0**2+x0*y0+y0*z0+z0*x0
            if p<10001:
                L[p]+=1
N=int(input())
for i in range(1,N+1):
    print(L[i])

Measured memory_bytes: 9940
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

main {
  vi v(2001);
  rep(i, 1001) rep(j, 1001) v[i + j]++;
  int n;
  while (cin >> n) {
    int c = 0;
    rep(i, 2001) if (0 <= n - i && n - i <= 2000) c += v[i] * v[n - i];
    cout << c << endl;
  }
}

Measured memory_bytes: 3108
using System;
using System.Text;

// テストケースの出力

public class ITP1_3_B
{
    public static void Main(string[] args)
    {
        //var exStdIn = new System.IO.StreamReader( "input.txt" );
        //System.Console.SetIn( exStdIn );

        int num = 1;

        while (true)
        {
            int input = int.Parse(Console.ReadLine());
            if (input == 0)
            {
                break;
            }
            Console.WriteLine($"Case {num++}: {input}");
        }
    }
}



Measured memory_bytes: 17952
#include<iostream>

using namespace std;

int N,A[100010],B[100010];

int main(){
    cin>>N;
    for(int i=1;i<=N+1;i++)
        cin>>A[i];
    for(int i=1;i<=N;i++)
        cin>>B[i];
    long long result = 0;
    for(int i=1;i<=N;i++)
    {
        if(A[i]>=B[i])
            result+=B[i];
        else
        {
            int t = A[i+1]-(B[i]-A[i]);
            if(t<0)
            {
                result+=A[i]+A[i+1];
                A[i+1]=0;
            }
            else
            {
                result+=B[i];
                A[i+1]= t;
            }
        }
    }
    cout<<result;
    return 0;
}




Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <iostream>
#include <cstring>
#include <cmath>
#include <unistd.h>
#include <vector>
#include <queue>
#include <stack>
#define PI 3.14159265358979323846

using namespace std;

int main()
{
	string frase;
	int c=0, max=0;

	cin >> frase;

	for(int i=0;frase[i]!='\0';i++)
	{
		if(frase[i]=='A' or frase[i]=='T' or frase[i]=='C' or frase[i]=='G')
			c++;
		else
		{
			if(c>max)
				max=c;
			c=0;
		}
	}
	if(c>max)
		max=c;

	cout << max << endl;

	return 0;
}

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

namespace JOI_1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            long ret = x[0];
            int[] span = new int[x[0] - 1];
            int mae = int.Parse(Console.ReadLine());
            for (int i = 0; i < x[0] - 1; i++)
            {
                int now = int.Parse(Console.ReadLine());
                span[i] = now - mae - 1;
                mae = now;
            }
            Array.Sort(span);
            for (int i = 0; i < x[0] - x[1]; i++) ret += span[i];
            Console.WriteLine(ret);
        }
    }
}


Measured memory_bytes: 10448
//ABC 153 E 
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
int H,N;
int A[10101],B[101010];
ll dp[20100];
void solve() {
	int i,j,k,l,r,x,y; 
	cin>>H>>N;
	for(i=0; i<20001; ++i) 
	   dp[i]=1LL<<60;
	dp[0]=0;
	for(i=0; i<N; ++i) {
		cin>>x>>y;    //Ai, Bi 
		for(j=0; j<H; ++j) 
		   dp[j+x] = min(dp[j+x],dp[j]+y);
	}
	ll mi=1LL<<60;
	for(i=H;i<=20000;i++) 
	   mi=min(mi,dp[i]);
	cout<<mi<<endl;	
}
int main(){
	int i;
	ios::sync_with_stdio(false), cin.tie(0);
	solve(); 
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

int N, M;
vector<int> p(100001, 0);
vector<int> idx[101010];
int f[101010];

class UnionFind {
	public:
		vector<int> par, rank;
		void init(int n) {
			par = vector<int>(n);
			rank = vector<int>(n);
			for (int i = 0; i < n; i++) par[i] = i, rank[i] = 0;
		}
		// 木の根を求める
		int root(int x) {
			return (par[x] == x) ? x : par[x] = root(par[x]);
		}
		// xとyの属する集合を併合
		void unite(int x, int y) {
			x = root(x), y = root(y);
			if (x == y)return;
 
			if (rank[x] < rank[y]) par[x] = y;
			else {
				par[y] = x;
				if (rank[x] == rank[y]) rank[x]++;
			}
		}
		// xとyが同じ集合に属するか否か
		bool same(int x, int y) {
			return root(x) == root(y);
		}
};


int main(void){
    
    scanf("%d %d", &N, &M);
    for(int i = 1; i <= N; ++i) scanf("%d", &p[i]);
    
    UnionFind uf;
    uf.init(N + 1);
    
    for(int i = 0; i < M; ++i){
        int x, y; scanf("%d %d", &x, &y);
        uf.unite(x, y);
    }
    
    for(int i = 1; i <= N; ++i) idx[uf.root(i)].push_back(i);
    
    int ans = 0;
    for(int i = 1; i <= N; ++i){
        for(auto j : idx[i]) f[j] = 1;
        for(auto j : idx[i]) if(f[p[j]]) ++ans;
        for(auto j : idx[i]) f[j] = 0;
    }
    printf("%d\n", ans);
    
    return 0;
}

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

int main() {
int A,B,C;
cin >>A>>B>>C;
if(A==B && B!=C)
{ 
  cout << "Yes" << endl;
  return 0;
}
if(C==B && A!=C)
{ 
  cout << "Yes" << endl;
  return 0;
}
if(A==C && B!=C)
{ 
  cout << "Yes" << endl;
  return 0;
}
else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
import java.text.*;
import java.math.*;
import java.util.*;

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

		num[0] = scan.nextInt();
		int hako = 0;
		int keta = 1;
		int w = 1;
		for(int i = 1;i <= num[0]; i++) {
			int x = i;
			if(i % 3 == 0) {
				System.out.print(" " + i);
			}else {
				/*while(true) {
					if(i / w == 0) break;
					keta++;
					w = w * 10;
				}*/
				while(x != 0) {
					if(x % 10 == 3) {
						System.out.print(" " + i);	
						break;
					}else {
						hako = x /w;
						x = x/10;
					}
					
				}
			}
		}
		System.out.println();
	}
}

Measured memory_bytes: 24280
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int w = Integer.parseInt(sc.next());
        int h = Integer.parseInt(sc.next());
        int x = Integer.parseInt(sc.next());
        int y = Integer.parseInt(sc.next());
        sc.close();
        String ans = ((long) w * h / 2.0) + " " + (x * 2 == w && y * 2 == h ? 1 : 0);
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#include <stdio.h>
void insertSort(int A[],int N) {
	int i, j, k, tmp, flag;
	flag = 0;
	
	for (k = 0; k < N; ++k) {
		printf("%d", A[k]);
		if (k != N-1) {
			printf(" ");
		} else {
			printf("\n");
		}
	}

	
	for (i = 1; i < N; ++i) {
		tmp = A[i];
//		printf("\n");
//		printf("%d\n", tmp);
		j = i - 1;
		flag = 1;
		while (j >= 0 && A[j] > tmp) {
			flag = 1;
			A[j+1] = A[j];
			j--;
		}
		A[j+1] = tmp;
		if (flag) {
			//		printf("\n");
			for (k = 0; k < N; ++k) {
				printf("%d", A[k]);
				if (k != N-1) printf(" ");
			}
			printf("\n");
		}
	}
}

int main(void)
{
	int A[100] = {0};
	int i, j, n;
	
	scanf("%d", &n);
	for (i = 0; i < n; ++i) {
		scanf("%d", &A[i]);
	}
	insertSort(A, n);
	return 0;
}

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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

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

    if (abs(a - c) <= d) {
        cout << "Yes";
    } else if (abs(a - b) <= d && abs(b - c) <= d) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
// ABC 107 B- Grid Compression
// 多次元配列

#include <bits/stdc++.h>
using namespace std;

int main() {
  int H, W;
  cin >> H >> W;
  // 入力ます目
  vector<vector<char>> data(H, vector<char> (W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> data.at(i).at(j);
    }
  }
  // 黒いますがあるかどうかboolで判断
  // 列および行をチェック
  vector<bool> row(H, false);
  vector<bool> col(W, false);
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (data.at(i).at(j) == '#') {
        row.at(i) = true;
        col.at(j) = true;
      }
    }
  }
  // 出力
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (row.at(i) == true && col.at(j) == true) {
        cout << data.at(i).at(j);
      }
      if (j == W-1 && row.at(i) == true) {
        cout << endl;
      }
    }
  }
}


Measured memory_bytes: 3616
#include <iostream>
#include <vector>

bool IsTriangle(const std::int64_t& l1, const std::int64_t& l2, const std::int64_t& l3)
{
    if (l1 == l2)
    {
        return false;
    }

    if (l2 == l3)
    {
        return false;
    }

    if (l3 == l1)
    {
        return false;
    }

    if (l1 + l2 <= l3)
    {
        return false;
    }

    if (l2 + l3 <= l1)
    {
        return false;
    }

    if (l3 + l1 <= l2)
    {
        return false;
    }

    return true;
}

int main()
{
    int n = 0;
    std::cin >> n;

    if (n < 3)
    {
        std::cout << 0;
        return 0;
    }

    std::vector<std::int64_t> lines(n);
    for (auto& line : lines)
    {
        std::cin >> line;
    }

    int tCount = 0;
    for (auto it1 = lines.begin(); it1 != (lines.end() - 2); ++it1)
    {
        for (auto it2 = it1 + 1; it2 != (lines.end() - 1); ++it2)
        {
            for (auto it3 = it2 + 1; it3 != lines.end(); ++it3)
            {
                if (IsTriangle(*it1, *it2, *it3))
                {
                    ++tCount;
                }
            }
        }
    }

    std::cout << tCount;

    return 0;
}

Measured memory_bytes: 3620
#include <stdio.h>
#include <stdlib.h>

#define P 1000000007


int ctr[26], index[26], index_num = 0;

long long int accum = 0;


void trace(long long int product, int level, int level_num, int pos)
{
    int i;
    
    
    if(level == level_num)
    {
        accum += product;
        accum %= P;
    }
    else
    {
        for(i=pos; i<index_num && level_num-level<=index_num-i; i++)
        {
            trace((product*ctr[index[i]])%P, level+1, level_num, i+1);
        }
    }
}

int main(void)
{
    int N;
    char *S;
    int i;
    
    
    scanf("%d", &N);
    
    S = (char*)malloc(sizeof(char)*(N+1));
    
    scanf("%s", S);
    
    
    for(i=0; i<26; i++)
    {
        ctr[i] = 0;
    }
    
    for(i=0; i<N; i++)
    {
        switch(S[i])
        {
            case 'a':
                ctr[0]++;
                break;
            case 'b':
                ctr[1]++;
                break;
            case 'c':
                ctr[2]++;
                break;
            case 'd':
                ctr[3]++;
                break;
            case 'e':
                ctr[4]++;
                break;
            case 'f':
                ctr[5]++;
                break;
            case 'g':
                ctr[6]++;
                break;
            case 'h':
                ctr[7]++;
                break;
            case 'i':
                ctr[8]++;
                break;
            case 'j':
                ctr[9]++;
                break;
            case 'k':
                ctr[10]++;
                break;
            case 'l':
                ctr[11]++;
                break;
            case 'm':
                ctr[12]++;
                break;
            case 'n':
                ctr[13]++;
                break;
            case 'o':
                ctr[14]++;
                break;
            case 'p':
                ctr[15]++;
                break;
            case 'q':
                ctr[16]++;
                break;
            case 'r':
                ctr[17]++;
                break;
            case 's':
                ctr[18]++;
                break;
            case 't':
                ctr[19]++;
                break;
            case 'u':
                ctr[20]++;
                break;
            case 'v':
                ctr[21]++;
                break;
            case 'w':
                ctr[22]++;
                break;
            case 'x':
                ctr[23]++;
                break;
            case 'y':
                ctr[24]++;
                break;
            case 'z':
                ctr[25]++;
                break;
        }
    }
    
    for(i=0; i<26; i++)
    {
        if(ctr[i] > 0)
        {
            index[index_num++] = i;
        }
    }
    
    
    for(i=1; i<=index_num; i++)
    {
        trace(1, 0, i, 0);
    }
    
    
    printf("%lld\n", accum);
        
        
    free(S);

    //system("pause");
    
    return 0;
}


Measured memory_bytes: 256
N = int(input())
AB_list = []
for i in range(N):
    a,b = map(int, input().split())
    AB_list.append([a,b])

AB_list_sorted = sorted(AB_list, key=lambda x: x[1])

output = 'Yes'
time = 0
for ab in AB_list_sorted:
    time += ab[0]
    if ab[1] < time:
        output = 'No'
        break

print(output)

Measured memory_bytes: 39596
#include<cstdio>
int main(void){
	char a[10];
	scanf("%s", a);
	if (a[0] == 'a' || a[0] == 'i' || a[0] == 'u' || a[0] == 'e' || a[0] == 'o') printf("vowel\n");
	else printf("consonant\n");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define F(i,s,e) for(int i=s;i<e;++i)

int main()
{
    long int a,b,k;
    cin >> a >> b >> k;
    if(a>=k){
        a-=k;
        k=0;
    }
    else{
        k-=a;
        a=0;
    }
    if(b>=k){
        b-=k;
    }
    else{
        k-=b;
        b=0;
    }
    cout << a << " " << b << endl;
    return 0;
}

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



int main() {
    vector<int>n(3);
    for(int i=0;i<3;i++){
        cin>>n.at(i);
    }
    
    sort(n.begin(),n.end());
    if(n.at(0)==n.at(1)){
        cout<<n.at(2);
    }else if(n.at(1)==n.at(2)){
        cout<<n.at(0);
    }
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long

using namespace std;

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

	ll N = 26;
	vector <ll> c(N);
	for (ll ii = 0; ii < N; ++ii){
		cin >> c[ii];
	}
	vector<vector<ll>> s(D, vector <ll> (N));
	for (ll ii = 0; ii < D; ++ii){
		for (ll jj = 0; jj < N; ++jj){
			cin >> s[ii][jj];
		}
	}

	//貪欲法
	vector <int> ans(D, 0);
	vector <int> last(N, -1);
	for (ll d = 0; d < D-1; ++d){
		//2日後の値を最大化する
		ll val = 0;
		ll idx = 0;
		for (int ii = 0; ii < N; ++ii){
			ll tmp = s[d][ii] + c[ii]*(d - last[ii]);
			for (int jj = 0; jj < N; ++jj){
				tmp += s[d+1][jj];
				if (jj == ii){
					tmp += c[jj];
				} else {
					tmp += c[jj]*(d+1 - last[jj]);
				}
				if (tmp > val){
					val = tmp;
					idx = ii;
				}
			}
		}
		ans[d] = idx + 1;
		last[idx] = d;
	}
	//最後の日
	ll d = D-1;
	ll val = 0;
	ll idx = 0;
	for (int ii = 0; ii < N; ++ii){
		ll tmp = s[d][ii] + c[ii]*(d - last[ii]);
		if (tmp > val){
			val = tmp;
			idx = ii;
		}
	}
	ans[d] = idx + 1;
	last[idx] = d;

	for (ll d = 0; d < D; ++d){
		cout << ans[d] << "\n";
	}


	return 0;
}


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

using namespace std;

typedef long long ll;

int main() {
	ll n, num;
	vector<ll> h;

	cin  >> n;
	
	for (ll i = 0; i < n; i++) {
		cin >> num;
		h.push_back(num);
	}

	vector<ll> sol(n, 0);

	sol[0] = 0;
	sol[1] = abs(h[1]-h[0]);

	for (ll i = 2; i < n; i++) {
		sol[i] = min(sol[i-1] + abs(h[i-1] - h[i]), sol[i-2] + abs(h[i-2] - h[i]));
	}

	cout << sol[n-1]  << endl;
	
	return 0;
}


Measured memory_bytes: 4984
import sys
sys.setrecursionlimit(10**6)
def input(): return sys.stdin.readline().strip()


def main():
    N, M, P = map(int, input().split())

    """
    あらかじめ各辺のコイン枚数からP引いておけば、求めるのは単純にコイン枚数の最大値となる。
    すなわちこれは「最長経路問題」に他ならない。
    するとコイン枚数を(-1)倍して「最短経路問題」を求めればよく典型問題に帰着。
        ダイクストラ　　　→　負辺があるのでダメ
        ベルマンフォード　→　O(VE)で解けるので今回はこれ
        ワ―シャルフロイド →　O(V^3)なので間に合わない

    ベルマンフォード復習：
        １．スタートする頂点をsとしてd[s] = 0、その他の頂点はd[v] = \inftyで初期化
        ２．重みwの辺u→vに対してd[v] = min(d[v], d[u] + w)
        ３．この更新を「すべての辺」（E本）に対して行う
        ４．２－３ステップをN（頂点数）回繰り返すと値の更新が（負閉路を除き）収束する
    
    ただし本問では負閉路検出後にそれが1-(負閉路)-Nのように頂点1と頂点Nの間にいることを
    確認する必要がある。
    """

    edges = [] # ベルマンフォードするなら頂点よりも辺が主役なので
    repn = [[] for _ in range(N)]
    reverse_repn = [[] for _ in range(N)]
    for _ in range(M):
        a, b, c = map(int, input().split())
        repn[a - 1].append(b - 1)
        reverse_repn[b - 1].append(a - 1)
        edges.append((a - 1, b - 1, P - c))

    """
    後々必要なので、頂点0「から」たどり着ける頂点と、
    頂点(N-1)「に」たどり着ける頂点をそれぞれ列挙する
    """

    reachable_from_1 = [0] * N
    reachable_to_N = [0] * N
    ok = [0] * N # 始点と終点の間にいる頂点（ここだけ考慮すれば十分）

    def dfs(v):
        if reachable_from_1[v]:
            return
        reachable_from_1[v] = 1
        for u in repn[v]:
            dfs(u)
    
    def reverse_dfs(v):
        if reachable_to_N[v]:
            return
        reachable_to_N[v] = 1
        for u in reverse_repn[v]:
            reverse_dfs(u)
    
    dfs(0)
    reverse_dfs(N - 1)
    for i in range(N):
        if reachable_from_1[i] and reachable_to_N[i]:
            ok[i] = 1

    """
    ここからベルマンフォード
    """

    d = [float("inf")] * N
    d[0] = 0
    step = 0
    update = True
    while update:
        update = False
        for i in range(M):
            a, b, cost = edges[i]
            if not ok[a]: continue
            if not ok[b]: continue
            new_cost = d[a] + cost
            if new_cost < d[b]:
                update = True
                d[b] = new_cost
        step += 1
        if step > N:
            print(-1)
            return
    print(max(0, -d[N - 1]))


if __name__ == "__main__":
    main()


Measured memory_bytes: 61916
#include<bits/stdc++.h>
#define endl "\n"
#define ll long long
#define eb emplace_back
#define sz(x) ((int)(x).size())
#define mo 100000000
using namespace std;
//Conditional Operator (condition?true part:false part) eg : cout<<(y<=3?"YES":"NO")<<endl;
ll getmul(ll n){ll int k{0};while(n>0){k+=n%10;n=n/10;}return k;}//Sum OF n DIGITS
int main(){
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     string s,t;
     cin>>s>>t;
     ll int ans{0};
     for(int i=0;i<sz(s);i++){
         if(s[i]!=t[i])
             ans++;
     }
     cout<<ans<<endl;
 return 0;    
}

Measured memory_bytes: 3796
#include<iostream>
using namespace std;
int main() {
	int n;
	int a[150000];
	bool b[150000] = { false };
	cin >> n;
	for (int i = 0; i < n; i++) { cin >> a[i+1]; }
	int light = 1;
	bool can = true;
	int count = 0;
	while (true) {
		if (b[light]) { can = false; break; }
		b[light] = true;
		light = a[light];
		count++;
		if (light == 2) { break; }
	}
	if (!can) { cout << -1 << endl; }
	else { cout << count << endl; }

}

Measured memory_bytes: 768
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    // 標準入力
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    // 標準入力数値配列用
    static int[] inputval() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        int[] intarray = new int[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    public static void main(String[] args) throws Exception {
	// write your code here
        int[] intArray = inputval();
        int n = intArray[0];
        int a = intArray[1];
        int b = intArray[2];
        int ans = 0;

        for (int i=1; i<=n; i++){
            String nStr = String.valueOf(i);
            int num = 0;
            for (int j=0; j<nStr.length(); j++){
                char numPart = nStr.charAt(j);
                num += Character.getNumericValue(numPart);
            }
            if (num >= a && num <=b){
                ans += i;
            }
        }

        System.out.println(ans);
    }

}



Measured memory_bytes: 22868
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
 
using namespace std;

signed main()
{
    fast;
    int a,b;
    cin>>a>>b;

    int x = b*10;
    int pos = -1;
    for ( int i = x ; i < x + 10 ; i++ )
    {
        if ( (i*2)/25 == a )
        {
            pos = i;
            break;
        }
    }

    cout<<pos<<endl;
    return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
win = []
for i in range(N):
    a = i+1
    count = 0
    while a < K:
        a = a*2
        count += 1
    A = (1/N) * (1/2)**count
    win.append(A)
B = sum(win)
print(B)

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

template <typename T>
void print(const T &v);

int main()
{
    string s;
    cin >> s;
    int n = s.size() - 1;
    ll ans = 0;
    for (int i = 0; i < pow(2, n); i++)
    {
        vector<int> bt;
        int cp = i;
        for (int j = 0; j < n; j++)
        {
            bt.push_back(cp % 2);
            cp /= 2;
        }
        string num;
        num.push_back(s[0]);
        for (int k = 0; k < n; k++)
        {
            if (bt[k] == 0)
            {
                num.push_back(s[k + 1]);
            }
            else
            {
                ans += stoll(num);
                num = s[k + 1];
            }
        }
        ans += stoll(num);
    }
    cout << ans << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}


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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

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

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;

signed main() {
  int n = read();
  vi vec(n);
  REP(i, n) vec[i] = read();
  int t = 0, sum = 0, tmp = 0, ans = 0;
  REP(i, n) {
    sum += vec[i];
    if (t && sum >= 0)
      tmp += sum + 1, sum = -1;
    else if (!t && sum <= 0)
      tmp += -1 * sum + 1, sum = 1;
    t ^= 1;
  }
  ans = tmp;
  t = 1, tmp = 0, sum = 0;
  REP(i, n) {
    sum += vec[i];
    if (t && sum >= 0)
      tmp += sum + 1, sum = -1;
    else if ((!t) && sum <= 0)
      tmp += -1 * sum + 1, sum = 1;
    t ^= 1;
  }
  print(min(ans, tmp));
}

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

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1<<25;
const ll INFL = 1223372036854775807;
const ll mod = 1000000007;

int n, A, B, C;

VI l;

int dfs(int i, int a, int b, int c) {
	if (i == n) {
		if (!a || !b || !c) return INF;
		return abs(a - A) + abs(b - B) + abs(c - C);
	}

	int res = dfs(i + 1, a, b, c);

	chmin(res, dfs(i + 1, a + l[i], b, c) + (a ? 10 : 0));
	chmin(res, dfs(i + 1, a, b + l[i], c) + (b ? 10 : 0));
	chmin(res, dfs(i + 1, a, b, c + l[i]) + (c ? 10 : 0));

	return res;
}



int main() {


	cin >> n >> A >> B >> C;

	
	REP(i, n) {
		int d;
		cin >> d;
		l.push_back(d);
	}



	cout << dfs(0, 0, 0, 0) << endl;
	
	return 0;


}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int A = in.nextInt();
        int B = in.nextInt();
        int C = in.nextInt();
        int X = in.nextInt();
        int sum =0;
        int count = 0;
        for(int i = 0; i <= A; i++){
            sum = 0;    
            for(int j = 0; j <= B; j++){
                for(int k = 0; k <= C; k++){
                    sum =500*i+100*j+ 50*k;
                    if(sum > X){
                        break;
                    } else if (sum == X){
                        count++;
                        break;
                    }
                }
            }
        }
        System.out.println(count);
    }

}

Measured memory_bytes: 22996
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int  i = scanner.nextInt();
        String s = scanner.next();
        cache.clear();
        //System.out.println(dp("WWRR", 0, "WWRR".length()-1));
        System.out.println(dp(s, 0, s.length()-1));
        /*long N = scanner.nextInt(),ans=0,i;
        //N*X -> 7*10^3+7*10^2+7*10^1+7 => 7(10^3+10^2+10^1+1) => 7(1 + 10*(10^2+10+1)) => 7(1+10+ 100*(10^2+10+1))
                                                                //7(1+10(1+10*(1+10*(1+10*())))

        if (N%7==0)
            N/=7;
        if (N%2==0) {
            System.out.println("-1");
            return;
        }

        //factor of 7?
        long cum = 0;
        for (int j = 1; j < N+10; j++) {
            cum = cum*10L+1;
            if (cum>N)
                cum=cum%N;
            if (cum==N || cum==0) {
                System.out.println(j);
                return;
            }
        }
        System.out.println("-1");
        /*
        7(1)
         7 + 10 * 7
            7 + 10 * 7 + 700
                1 + 10 + 100
         **/
        //10^x-1/9 = N*X/7, 10^x = N*X*9/7+1  =>
        //N*X => 0, 7, 7*11 , 7 * 111
        //BigInteger num = new BigInteger("7"), N1 = new BigInteger(N+""), N2 = BigInteger.ONE;
        /*for (i = 1; i <= N&&N%2==1; i++) {
            if (num.mod(N1).equals(BigInteger.ZERO))
                break;
            N2=N2.multiply(BigInteger.TEN).add(BigInteger.ONE);
            num=num.multiply(N2);
        }
        System.out.println((i==N+1||N%2==0)?"-1":i);*/
    }

    static Map<String, Integer> cache = new HashMap<>();
    private static int dp(String s, int i, int i1) {
        //System.out.println(s + "\t" + i + "\t" + i1);
        if (i>=i1)return 0;
        if (s.charAt(i)=='R')
            return dp(s, i+1,i1);
        if (s.charAt(i1)=='W')
            return dp(s, i,i1-1);
        String key = i + " " + i1;
        if (cache.containsKey(key))
            return cache.get(key);
        int ans = Math.min(
                1+dp(s, i+1,i1-1),Integer.MAX_VALUE
                //1+dp(s, i,i1-1)
        );
        cache.put(key, ans);
        return ans;
    }

}


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

#define ALL(c) (c).begin(), (c).end()
#define CALL(c) (c).cbegin(), (c).cend()
#define RALL(c) (c).rbegin(), (c).rend()
#define CRALL(c) (c).crbegin(), (c).crend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

const int INF = INT_MAX;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};

using PII = pair<int, int>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;
template<class T, int W=255> using A = array<T, W>;
template<class T, int W=255, int H=255> using A2 = array<array<T, W>, W>;

std::string s;

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cin >> s;
    int ev = 0;
    int od = 0;
    REP(i, s.size()) {
        if(i % 2 == 0) {
            if(s[i] == '0') od++;
            if(s[i] == '1') ev++;
        } else {
            if(s[i] == '0') ev++;
            if(s[i] == '1') od++;
        }
    }
    cout << min(ev, od) << "\n";
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <queue>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
typedef pair<ll,ll> P;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
#define setpre(n) fixed << setprecision(n)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(cv *a, cv *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(cv *a, cv *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(cv *left, cv *right) {return strcmp((char *)left,(char *)right);}
int downchar(cv *left, cv *right) {return strcmp((char *)right,(char *)left);}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1){
      res *= a; if(mod>=1) res %= mod;
    }
    a *= a; if(mod>=1) a %= mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
  
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0,h,w;
  int a[LIMIT2]={0};
  ll now[2],dst[2];
  string s[1010];
  using VP = pair<ll,P>;
  //deque<pair<ll,P> > que;
  priority_queue<VP,vector<VP>,greater<VP> > que;
  ll dist[1010][1010];
  
  cin >> h >> w;
  cin >> now[0] >> now[1];
  now[0]--;now[1]--;
  cin >> dst[0] >> dst[1];
  dst[0]--;dst[1]--;
  rep(i,h){
    cin >> s[i];
  }
  rep(i,h){
    rep(j,w){
      dist[i][j]=1LL<<60;
    }
  }
  dist[now[0]][now[1]] = 0;
  que.push({0,{now[0],now[1]}});
  while(!que.empty()){
    auto p = que.top();
    que.pop();
    auto d = p.first;
    auto x = p.second.first;
    auto y = p.second.second;
    if(dist[x][y]<d) continue;
    for(j=max(0,x-2);j<=min(h-1,x+2);j++){
      for(k=max(0,y-2);k<=min(w-1,y+2);k++){
        if(s[j][k]=='#' || (j==x&&k==y)) continue;
        else if(dist[j][k]<=d) continue;
        if(llabs(j-x)+llabs(k-y)<=1){//歩いて移動
          dist[j][k] = d;
          que.push({d,{j,k}});//01BFS -> Dijkstra
        }else{
          dist[j][k] = d+1;
          que.push({d+1,{j,k}});
        }
      }
    }
  }
  result = dist[dst[0]][dst[1]];
  cout << (result==1LL<<60 ? -1 : result) << endl;
  return 0;
}

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

#define endl "\n"
#define int long long
#define vec(x) vector<x>
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pair<int,int>>
#define matrix(x) vector<vector<x>>
#define all(v) v.begin(),v.end()
#define mem(a,b) memset(a, b, sizeof a)
#define setBits(n) __builtin_popcountll(n)
#define ff first
#define ss second
#define print(x) for(auto it:x) cout<<it<<" ";
#define dbg(x) cerr<<#x<<" :: "<<x<<endl;
#define dbg2(x,y) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
const int INF = 1e9;
const int MOD = 1e9 + 7; 
const double pi = acos(-1);
int power(int a,int b,int m=MOD)
{int ans=1;while(b>0){if(b&1)ans=(ans*a)%m;a=(a*a)%m;b>>=1;}
return ans;}
int dir[]={-1, 0, 1, 0, -1};
int dx[]={1,1,0,-1,-1,-1, 0, 1};
int dy[]={0,1,1, 1, 0,-1,-1,-1};

const int N = 1e5+1;

void solve()
{
	string s;
	int i,k;
	cin>>k>>s;
	if(s.size()<=k)
	cout<<s;
	else
	cout<<s.substr(0,k)<<"...";
}

int32_t main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int t;
	t=1;
	//cin>>t;
	while(t--)
		solve();
}

Measured memory_bytes: 3632
n = gets.chomp.to_i
as = gets.chomp.split.map(&:to_i)
bs = gets.chomp.split.map(&:to_i)

cnt = 0
rem = 0
(0...n).each do |i|
    ki = [as[i], bs[i]].min
    rem = bs[i] - ki
    kn = [as[i + 1], rem].min
    as[i+1] = as[i+1] - kn
    cnt = cnt + ki + kn
end

puts cnt


Measured memory_bytes: 21788
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector<int> a(3);
  REP(i, 3){
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  REP(i, 2){
    cout << a.at(i) << " ";
  }
  cout << a.at(2) << endl;
}



Measured memory_bytes: 3100
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            BigInteger[] A = Console.ReadLine().Split(" ").Select(x => BigInteger.Parse(x)).ToArray();
            BigInteger ans = 0;
            for (int i = 1; i < N; i++)
            {
                if (A[i - 1] > A[i])
                {
                    BigInteger tmp = A[i - 1] - A[i];
                    A[i] += tmp;
                    ans += tmp;
                }
            }
            Console.WriteLine(ans);
        }
    }
}
//int[] N = Console.ReadLine().Split(" ").Select(x => int.Parse(x)).ToArray();

Measured memory_bytes: 66948
import bisect
n,k = map(int, input().split())
x = list(map(int, input().split()))
z = bisect.bisect_left(x,0)

ans=10**12
s=z-k
if s < 0:
  s=0
g=z+1
if g+k >= n:
  g=n-k+1
for i in range(s,g):

  xl=x[i]
  xr=x[i+k-1]
  ans=min(ans,abs(xr)+abs(xr-xl),abs(xl)+abs(xr-xl))
print(ans)

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

alias P = Tuple!(long, "i", long, "p");

void main()
{
    auto N = readln.chomp.to!long;
    P[] ps;
    foreach (i, p; readln.split.to!(long[])) ps ~= P(i.to!long+1, p);
    sort!"a.p > b.p"(ps);
    auto T = redBlackTree(0, ps[0].i, N+1);
    long res;
    foreach (i; 1..N) {
        auto p = ps[i].p;
        auto x = ps[i].i;
        {
            auto l = x;
            auto r = T.upperBound(x).front;
            if (r != N+1) {
                auto ll = T.lowerBound(l).back;
                auto rr = T.upperBound(r).front;
                res += (l-ll) * (rr-r) * p;
            }
        }
        {
            auto r = x;
            auto l = T.lowerBound(x).back;
            if (l != 0) {
                auto ll = T.lowerBound(l).back;
                auto rr = T.upperBound(r).front;
                res += (l-ll) * (rr-r) * p;
            }
        }
        T.insert(x);
    }
    writeln(res);
}

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

int main() {
	int height, width;
	while (true) {
		cin >> height >> width;
		if (height == 0 && width == 0)
			break;
		for (int i = 0; i < height; i++) {
			for (int j = 0; j < width; j++) {
				cout << '#';
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include <cmath>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define mkpr(x1,x2) make_pair(x1,x2)
typedef long long int ll;


//stack<char> stk;
//set<ll> sll;
//set<pair<ll,ll>> spll;
//map<string,ll> mp;
//map<pair<ll,ll>,ll>::iterator iter;
//map<ll,ll> mp;
//deque<ll> deq;
//vector<ll> vll;
ll num[ten5];
//priority_queue<ll> pq;          //decreasing

int main(void)
{
    ll m,n,i,j,k=0,d,re=0;
    string s;
    cin>>n>>k>>d;
    if(n%k==0)
        cout<<n/k*d;
    else
        cout<<(n/k+1)*d;
    return 0;
}





Measured memory_bytes: 3624
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int sed(int N) {
    int a = N;
    int c = 0;
    bool b = true;
    while(b){
        if (a == 0) {
            b = false;
        }
        c += a % 10;
        a /= 10;
    }
    return c;
}
int main() {
    int N; cin >> N;
    if (N % sed(N) == 0) printf("%s\n", "Yes");
    else printf("%s\n", "No");
}


Measured memory_bytes: 3648
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#define Len 100005
using namespace std;

typedef struct pp{
	char name[100];
	int ti;
} P;

P Q[Len];
int head ,tail,N;

void enqueue(P x){//typedef 的作用这时候体现出来了 
	Q[tail] = x;
	tail = (tail+1)% Len; 
}
P dequeue(){
	P x = Q[head];
	head = (head +1)% Len;
	return x;
}

int main(){
	int sum_time = 0;
	int cu_time;
	int q;
	P u;
	cin >> N >> q;
	
	for (int i = 1; i<=N;i++){
		scanf("%s",Q[i].name);
		scanf("%d",&Q[i].ti);
	}
	head = 1; tail = N+1;
	while(head!=tail){
		u = dequeue();
		cu_time = min(q,u.ti);
		u.ti -= cu_time;
		sum_time += cu_time;
		if(u.ti > 0){
			enqueue(u);
		}
		else {
			printf("%s %d\n",u.name,sum_time);
		}
	}
	return 0; 
}



Measured memory_bytes: 13276