akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define repd(i,a,b) for (ll i = (a); i < (b); i++)
#define INF LLONG_MAX
#define mod 1000000007
typedef long long ll;

int main(void)
{
	ll N, K;
	cin >> N >> K;
	if(N%K==0)
	{
	    cout << 0 << endl;
	    return 0;
	}
	if(N>K) N = N % K;
	ll pre = abs(N-K);
	cout << min(N,pre);
	return 0;
}


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

long long A[200005];

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

    int N, K;
    cin >> N >> K;

    long long sum = 0;

    for(int i=1; i<=N; i++)
    {
        cin >> A[i];
        A[i] += A[i-1] + 1;
    }

    for(int i=K; i<=N; i++)
        sum = max(sum, A[i] - A[i-K]);

    cout << fixed << setprecision(9) << sum / 2.0 << "\n";
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cassert>
//#include <cmath>
//#define NDEBUG
int main(void){
	using namespace std;
	static const int INPUT_N_MIN = 0;
	static const int INPUT_N_MAX = 10000;
	static const int INPUT_A_MIN = -1000000;
	static const int INPUT_A_MAX =  1000000;
	int ans_min = INPUT_A_MAX;			/* 最小値 */
	int ans_max = INPUT_A_MIN;			/* 最大値 */
	long ans_sum = 0;					/* 合計値 100000*1000まで対応のためlong */
	int input_n = 0;
	/* 整数の個数nを入力 */
	cin >> input_n;
	
	/* 入力値の前提条件 最大・最小の制限*/
	assert (INPUT_N_MIN < input_n && input_n <= INPUT_N_MAX);
	
	int input_a[input_n];
	
	/* 計算する整数a群を入力 */
	for (int i = 0; i < input_n; i++){
		
		/* 入力値の前提条件 最大・最小の制限*/
		cin >> input_a[i];
		assert (INPUT_A_MIN <= input_a[i] && input_a[i] <= INPUT_A_MAX);
		
		/* 最大・最小値の更新判定 */
		if(input_a[i] < ans_min){
			ans_min = input_a[i];		/* 最小値更新 */
		}
		if(input_a[i] > ans_max){
			ans_max = input_a[i];		/* 最大値更新 */
		}
		
		/* 合計値に加算 */
		ans_sum = ans_sum + static_cast<long>(input_a[i]);
	}
	
	/* 出力 */
	cout << ans_min << " " << ans_max << " " << ans_sum << endl;
	
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<double> v;
  for ( int i = 0; i < n; i++ ) {
    double t;
    cin >> t;
    v.push_back(t);
  }
  sort(v.begin(), v.end());

  for ( int i = 1; i < n; i++ ) {
    v[i] = (v[i-1]+v[i])/2.0;
    sort(v.begin()+1, v.end());
  }

  printf("%.14f\n", v[n-1]);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)
#define INF 1<<29;


int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int max_a = *max_element(a.begin(),a.end());
    int min_a = *min_element(a.begin(),a.end());
    cout << max_a-min_a << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }
        
        int ans = 0;
        if (n == 1) {
            ans = Math.abs(array[n-1] - b);
        } else {
            ans = Math.max(Math.abs(array[n-2] - array[n-1]), Math.abs(array[n-1] - b));
        }
        System.out.println(ans);
    }
}


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

#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end() 
#define sz(v) (int)((v).size())
#define fs first
#define sd second

typedef long long ll;

typedef pair < int, int > pi;
typedef pair < pi, int > ppi;

typedef vector < int > vi;
typedef vector < vector < int > > vvi;
typedef vector < pi > vpi;
typedef vector < vpi > vvpi;
typedef vector < ppi > vppi;

void fast() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}

void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}

#ifdef LOCAL
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

double get_time() {
	return 1.0 * clock() / CLOCKS_PER_SEC;
}

const int MOD = 998244353;

const int MAX = 2E5 + 100;
int f[MAX];

void upd(int pos, int del) {
	for(; pos < MAX; pos |= pos + 1) {
		f[pos] = (f[pos] + del) % MOD;
		if(f[pos] < 0)
			f[pos] += MOD;
	}
}

int get(int pos) {
	int ret = 0;
	for(; pos >= 0; pos = (pos & (pos + 1)) - 1)
		ret = (ret + f[pos]) % MOD;
	return ret;
}


int main() {
	int n, k;
	cin >> n >> k;
	vector<int> l(n), r(n);
	for(int i = 0; i < k; i++) {
		cin >> l[i] >> r[i];
	}

	upd(0, 1);
	upd(1, -1);

	// cout << get(1) << '\n';

	for(int i = 0; i < n; i++) {
		for(int j = 0; j < k; j++) {
			int nl = i + l[j], nr = i + r[j];
			if(nl > n)
				continue;
			nr = min(nr, n - 1);
			upd(nl, get(i));
			upd(nr + 1, -get(i));
			// debug(nl, nr);
		}

		// for(int j = 0; j < n; j++)
		// 	cout << get(i) << ' ';
		// cout << '\n';
	}

	cout << get(n - 1) << '\n';
}


Measured memory_bytes: 5600
#![allow(unused_imports)]
#![allow(dead_code)]

use proconio::input;
use proconio::marker::{Bytes, Chars};
use std::collections::*;

fn main() {
    input! {
        n:usize,
    }
    let rem = n % 1000;
    let ans = if rem == 0 { 0 } else { 1000 - rem };
    println!("{}", ans);
}

Measured memory_bytes: 2136
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int tmp = n;
    int f = 0;
    while(tmp != 0){
      f += tmp % 10;
      tmp /= 10;
    }
    System.out.println(n % f == 0 ? "Yes" : "No");
  }
}

Measured memory_bytes: 23124
#include <stdio.h>
#include <cstring>

main(){
  while(1){

    int w,h;
    scanf("%d%d", &w,&h);

    if(w==0&&h==0) break;

    int dp[w][h];

    memset(dp, -1, sizeof(dp));

    int n;
    scanf("%d", &n);

    int x,y;
    for(int i=0;i<n;i++){
      scanf("%d%d",&x,&y);
      dp[x-1][y-1] = 0;
    }

    int k=1;
    for(int i=0;i<w;i++){
      if(!dp[i][0]) k=0;
      dp[i][0] = k;
    }
    k=1;
    for(int i=0;i<h;i++){
      if(!dp[0][i]) k=0;
      dp[0][i] = k;
    }

    // for(int i=0;i<w;i++){
    //   for(int j=0;j<h;j++){
    //     printf("%2d ", dp[i][j]);
    //   }
    //   puts("");
    // }

    for(int i=1;i<w;i++){
      for(int j=1;j<h;j++){
        if(dp[i][j]==-1){
          dp[i][j] = dp[i-1][j] + dp[i][j-1];
        }
      }
    }

    printf("%d\n", dp[w-1][h-1]);

  }
}

Measured memory_bytes: 0
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class D
{
	public static void Main()
	{
		int N = GetInt();
		var cities = new List<Tuple<int, int, int>>(N);
		for(int i = 0; i < N; i++)
			cities.Add(Tuple.Create(GetInt(), GetInt(), i));

		var edges = new List<Edge>(2 * N);

		cities.Sort((p, q) => p.Item1 - q.Item1);
		for(int i = 0; i < N - 1; i++)
		{
			int a = cities[i].Item3;
			int c = cities[i+1].Item3;
			edges.Add(new Edge(a, c, cities[i+1].Item1 - cities[i].Item1));
		}

		cities.Sort((p, q) => p.Item2 - q.Item2);
		for(int i = 0; i < N - 1; i++)
		{
			int b = cities[i].Item3;
			int d = cities[i+1].Item3;
			edges.Add(new Edge(b, d, cities[i+1].Item2 - cities[i].Item2));
		}

		Console.WriteLine(Kruskal(N, edges));
	}

	public static int Kruskal(int N, List<Edge> edges)
	{
		edges.Sort((x, y) => x.Cost - y.Cost);
		var uf = new UnionFind(N);
		int res = 0;
		for(int i = 0; i < edges.Count; i++)
		{
			Edge edge = edges[i];
			if(!uf.IsSame(edge.S, edge.T))
			{
				uf.Merge(edge.S, edge.T);
				res += edge.Cost;
			}
		}
		return res;
	} 
}


public struct Edge
{
	public int S;
	public int T;
	public int Cost;

	public Edge(int s, int t, int cost)
	{
		S = s;
		T = t;
		Cost = cost;
	}
}


public class UnionFind
{
	private int[] par = null;
	private int[] rank = null;
	private int[] ccSize = null;
	
	public UnionFind(int n)
	{
		par = new int[n];
		rank = new int[n];
		ccSize = new int[n];
		for(int i = 0; i < n; i++)
		{
			par[i] = i;
			rank[i] = 0;
			ccSize[i] = 1;
		}
	}

	public bool IsSame(int x, int y)
	{
		return (Root(x) == Root(y));
	}

	public int Root(int x)
	{
		if(par[x] == x)
			return x;

		int r = Root(par[x]);
		par[x] = r;
		return r;
	}
	
	public bool Merge(int x, int y)
	{
		int rx = Root(x);
		int ry = Root(y);
		if(rx == ry)
			return false;
		
		if(rank[rx] < rank[ry])
		{
			int tmp = rx;
			rx = ry;
			ry = tmp;
		}
		else if(rank[rx] == rank[ry])
			rank[rx]++;

		par[ry] = rx;
		ccSize[rx] = ccSize[rx] + ccSize[ry];
		return true;
	}

	public int Size(int x)
	{
		return ccSize[Root(x)];
	}
}


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

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

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}

Measured memory_bytes: 27068
#include <iostream>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int X = (A); X <= (Y);++X)
#define _rep2(X, Y) for (int X = 0; X < (Y); ++X)
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X, Y) for (int X = (Y-1); X >= 0; --X)
#define len(X) ((int)(X).size())
using namespace std;
typedef long long ll;

const int MAX_N = 50, MAX_A = 50;
int N, A;
int x[MAX_N + 1];
ll dp[MAX_N + 1][MAX_N + 1][MAX_N * MAX_A + 1];

int main() {
    cin >> N >> A;
    rep(i, 1, N) cin >> x[i];

    rep(i, N) dp[i][0][0] = 1;

    rep(i, 1, N) {
        rep(j, 1, i) {
            rep(k, 1, N * A) {
                if (k < x[i]) {
                    dp[i][j][k] = dp[i - 1][j][k];
                } else {
                    dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - x[i]];
                }
            }
        }
    }

    ll ans = 0;
    rep(j, 1, N) {
        ans += dp[N][j][j * A];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 49024
import java.util.*;

public class Main {
    static List<Room> lr;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        lr = new ArrayList<>(N+1);
        for(int t=0; t<=N; t++) {
            Room r = new Room(t);
            lr.add(r);
        }
        for(int i=1; i<=M; i++) {
            int A = sc.nextInt();
            int B = sc.nextInt();
            lr.get(A).connectTo(B);
            lr.get(B).connectTo(A);
        }

        Queue<Room> qr = new LinkedList<>();
        Room firstRoom = lr.get(1);
        firstRoom.sirube = 0;
        firstRoom.steps = 1;
        qr.add(firstRoom);
        while(true) {
            Room r = qr.poll();
            if(r==null) break;
            for(int ind : r.connected) {
                Room rrr = lr.get(ind);
                if(rrr.sirube!=-1) continue;
                rrr.sirube = r.index;
                rrr.steps = r.steps + 1;
                qr.add(rrr);
            }
        }
//        for(Room r : lr) {
//            System.out.printf("id:%d, sirube:%d, steps:%s\n", r.index, r.sirube, r.steps);
//        }
        System.out.println("Yes");
        for(int i=2; i<=N; i++) {
            System.out.println(lr.get(i).sirube);
        }
    }

    static class Room {
        int index;
        int sirube = -1;
        int steps = Integer.MAX_VALUE;

        List<Integer> connected = new ArrayList<>();
        Room(int i) {
            this.index = i;
        }

        void connectTo(int target) {
            connected.add(target);
        }
    }
}


Measured memory_bytes: 79756
#include<bits/stdc++.h>
using namespace std;
const int N=(1<<20)+5;
int lim=1,M=924844033,a[N],r[N],fac[N],inv[N],b[N],tot,h[N],sz[N],g=5,gi=554906420,n,i,x,y,l;
struct node{
	int to,ne;
}e[N];
inline int mul(int x,int y){return 1ll*x*y%M;}
inline int inc(int x,int y){x+=y;if(x>=M)x-=M;return x;}
inline int dec(int x,int y){x-=y;if(x<0)x+=M;return x;}
void add(int x,int y){e[++tot]={y,h[x]},h[x]=tot;}
int pw(int x,int y){
	int z=1;
	for (;y;y>>=1,x=1ll*x*x%M)
		if (y&1) z=1ll*z*x%M;
	return z;
}
int Inv(int x){return pw(x,M-2);}
void dfs(int u,int fa){
	sz[u]=1;
	for (int i=h[u],v;i;i=e[i].ne)
		if ((v=e[i].to)!=fa) dfs(v,u),sz[u]+=sz[v],a[sz[v]]++;
	a[n-sz[u]]++;
}
void ntt(int *a,int op){
	for (int i=0;i<lim;i++)
		if (i<r[i]) swap(a[i],a[r[i]]);
	for (int mid=1,pp=M-1>>1;mid<lim;mid<<=1,pp>>=1)
		for (int R=mid<<1,j=0,wn=pw(op==1?g:gi,pp);j<lim;j+=R)
			for (int k=0,w=1;k<mid;k++,w=mul(w,wn)){
				int x=a[j|k],y=mul(w,a[j|k|mid]);
				a[j|k]=inc(x,y);
				a[j|k|mid]=dec(x,y);
			}
	if (op==-1){
		int inv=Inv(lim);
		for (int i=0;i<lim;i++) a[i]=mul(a[i],inv);
	}
}
int main(){
	scanf("%d",&n);
	for (i=1;i<n;i++) scanf("%d%d",&x,&y),add(x,y),add(y,x);
	dfs(1,0);
	fac[0]=1,a[0]=0;
	for (i=1;i<=n;i++) fac[i]=1ll*fac[i-1]*i%M,a[i]=1ll*a[i]*fac[i]%M;
	b[0]=inv[n]=Inv(fac[n]);
	for (i=n-1;~i;i--) inv[i]=1ll*inv[i+1]*(i+1)%M,b[n-i]=inv[i];
	for (;lim<=n+n;lim<<=1,l++);
	for (i=0;i<lim;i++) r[i]=(r[i>>1]>>1)|((i&1)<<(l-1));
	ntt(a,1),ntt(b,1);
	for (i=0;i<lim;i++) a[i]=1ll*a[i]*b[i]%M;
	ntt(a,-1);
	for (i=1;i<=n;i++) printf("%lld\n",(1ll*fac[n]*inv[i]%M*inv[n-i]%M*n%M-1ll*inv[i]*a[n+i]%M+M)%M);
}

Measured memory_bytes: 34688
#include <stdio.h>
#define MAX(x, y) ((x)>(y)?(x):(y))

int main() {
    int n;
    scanf("%d", &n);
    int v[111], c[111];
    for (int i = 0; i < n; i++) scanf("%d", v + i);
    for (int i = 0; i < n; i++) scanf("%d", c + i);
    
    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans += MAX(v[i] - c[i], 0);
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstdint>
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(){

int a,b;

cin >> a >> b;

cout << 40 << " " << 100 << endl;

for(int i = 0; i<20; i++){
 for(int j = 0; j<100; j++){
  if( j % 2 == 0 && a > 1 && i % 2 == 0) { cout << "."; a--;}
  else cout <<"#";
   }
 cout << endl;
 }

for(int i = 20; i<40; i++){
 for(int j = 0; j<100; j++){
  if( j % 2 == 0 && b > 1 && i % 2 == 1) { cout << "#"; b--;}
  else cout <<".";
   }
 cout << endl;
 }
return 0;
}

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

vector<vector<ll> > dp;

ll fun(vector<ll> &d,vector<ll> &p,ll h,ll n)
{
	if(h<=0)
	{
		return 0;
	}

	if(n==0)
	{
		ll temp=INT_MAX;
		return temp;
	}

	if(dp[n][h]!=-1)
	{
		return dp[n][h];
	}

	

	dp[n][h]=min(fun(d,p,h,n-1),p[n-1]+fun(d,p,h-d[n-1],n));
	return dp[n][h];

}


int main()
{
ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	//freopen("input.txt","r",stdin);
#endif

	
		ll h,n;
		cin>>h>>n;
		vector<ll> d(n);
		vector<ll> p(n);
		dp.resize(n+1,vector<ll>(h+1,-1));
		for(ll i=0;i<n;i++)
		{
			cin>>d[i];
			cin>>p[i];
		}
		

		cout<<fun(d,p,h,n)<<endl;


	
	return 0;
}

Measured memory_bytes: 81576
#include<bits/stdc++.h>
#define io ios_base::sync_with_stdio(false); cin.tie(NULL);

#define N 10000
#define nl "\n"
#define f first
#define s second
#define pi acos(-1.0)
#define MOD 1000000007
#define pb push_back

typedef long long ll;
typedef double db;

using namespace std;

int main()
{
    io;
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt" , "w" , stdout);

    ///Let the showdown begin


    ll a,b,c,d;
    cin >> a >> b >>c >> d;

    ll res1 = a*c;
    ll res2 = a*d;
    ll res3 = b*c;
    ll res4 = b*d;

    ll ans1=max(res1,res2);
    ll ans2=max(res3,res4);
    ll out = max(ans1,ans2);

    cout << out << nl;
    ///Happily DONE

    return 0;
}


Measured memory_bytes: 3648
/* 159B */
#include<bits/stdc++.h>
using namespace std;
int main ()
{
    string s;
    cin>>s;
    int f1=1,n1,f2=1,n2,f3=1;
    if(s.size()%2)
    {
        n1=(s.size()-1)/2;
        n2=(s.size()+3)/2;
    }
    else
    {
        n1=s.size()/2;
        n2=s.size()/2;
    }
    //cout<<n1<<" "<<n2;
    for (int i=0;i<n1/2;i++)
    {
        //cout<<i<<" "<<n1-i<<endl;
        if(s[i]==s[n1-i-1]) f1=1;
        else 
        {
            f1=0;
            goto end;
        }
    }
    
    for (int i=n2;i<(s.size()-n2)/2 + n2;i++)
    {
        //cout<<i<<" "<<s.size()-i+n2<<endl;
        if(s[i-1] == s[s.size()-i+n2-1]) f2=1;
        else 
        {
            f2=0;
            goto end;
        }
    }
    for (int i=0;i<s.size()/2;i++)
    {
        //cout<<i<<" "<<s.size()-i<<endl;
        if(s[i]==s[s.size()-i-1]) f3=1;
        else
        {
            f3=0;
            break;
        }
    }
    end:
    if(f1 && f2 && f3) cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> pii;
typedef std::pair<long long, long long> pll;

using namespace std;

const long long MOD = 1000000007;

//ワーシャルフロイド法で連続グラフの各ノード間の距離を求める.
void warshallFloyd(int** graph, int n) {
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			for (int k = 0; k < n; ++k) {
				graph[j][k] = min(graph[j][k], graph[j][i] + graph[i][k]);
			}
		}
	}
}

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

	int n, m;
	ll l;
	cin >> n >> m >> l;

	int** graph;
	graph = new int*[n];
	rep(i, n) {
		graph[i] = new int[n];

		rep(j, n) graph[i][j] = MOD;
	}

	rep(i, m) {
		int a, b;
		ll c;
		cin >> a >> b >> c;

		graph[a - 1][b - 1] = c;
		graph[b - 1][a - 1] = c;
	}

	warshallFloyd(graph, n);

	rep(i, n) {
		rep(j, n) {
			if (graph[i][j] > l) graph[i][j] = MOD;
			else graph[i][j] = 1;
		}
	}

	warshallFloyd(graph, n);

	int q;
	cin >> q;
	rep(i, q) {
		int s, t;
		cin >> s >> t;
		if (graph[s - 1][t - 1] >= MOD) cout << -1 << "\n";
		else cout << graph[s - 1][t - 1] - 1 << "\n";
	}

	return 0;
}


Measured memory_bytes: 896
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap};

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;

fn main() {
    input! {
        a: i64, b: i64, c: i64,
    }

    let mut ans = max(0, c - (a - b));
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <stdio.h>
#include <stdlib.h>

#define repd(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  repd(i,0,n)

using namespace std;

int main(){
    int n;
    cin >> n;
    int ans = 0;
    rep(i, n){
        if ( to_string(i+1).size() % 2 == 1) ans++;
        // cout << i << " " << ((i+1)/10) % 2 << endl;
    }
    cout << ans << endl;

    return 0;
}

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

int main() {
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> card;
	for (int i = 0, a; i < n; i++) {
		cin >> a;
		card.emplace_back(a, 1);
	}
	for (int i = 0, b, c; i < m; i++) {
		cin >> b >> c;
		card.emplace_back(c, b);
	}
	sort(card.begin(), card.end(), [](auto &a, auto &b) {
		return a.first > b.first;
	});

	long long sum = 0;
	for (int i = 0, count = 0, num; count < n; i++) {
		num = min(n - count, card[i].second);
		count += num;
		sum += (long long) card[i].first * num;
	}
	cout << sum << endl;
}


Measured memory_bytes: 2420
a,b,c=[int(x) for x in input().split()]
if a<=b<=c:
    print(a,b,c)
elif a<=c<=b:
    print(a,c,b)
elif b<=a<=c:
    print(b,a,c)
elif b<=c<=a:
    print(b,c,a)
elif c<=a<=b:
    print(c,a,b)
elif c<=b<=a:
    print(c,b,a)


Measured memory_bytes: 5604
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1001001001;

vector<int> to[100005];

int main() {
  int n, m;
  cin >> n >> m;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }

  queue<int> q;
  vector<int> dist(n, INF);
  vector<int> pre(n, -1);
  q.push(0);
  dist[0] = 0;

  while(!q.empty()) {
    int v = q.front(); q.pop();
    for(int u : to[v]) {
      if(dist[u] != INF) continue;
      dist[u] = dist[v]+1; // n = 0 の場合は？
      pre[u] = v;
      q.push(u);
    }
  }

  cout << "Yes" << endl;
  rep(i,n) {
    if(i == 0) continue;
    int ans = pre[i];
    ans++;
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 10624
//----------------------------------------------------------------------
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
//----------------------------------------------------------------------

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(void) {
    int n;
    cin >> n;
    vector<int> a(n,0);
    map<int, ll> m;
    for(int i=1; i<n; i++) {
        int a; cin >> a;
        m[a]++;
    }

    for(int i = 1; i<=n; ++i) {
        cout << m[i] << endl;
    }
    
    return 0;
}

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 29)
#define MOD 1000000007
//int dx[4] = {1,0,0,-1};
//int dy[4] = {0,1,-1,0};




int main(){
  
  int n;
  ll res = 0;
  cin >> n;
  map<pair<char,char>,int> mp;
  for(int i = 1;i <= n;i++){
    string s = to_string(i);
    mp[make_pair(s[0],s[s.size()-1])]++;
  }
  for(int i = 1;i < 10;i++){
    for(int j = 1;j < 10;j++){
      res += mp[make_pair('0'+i,'0'+j)]*mp[make_pair('0'+j,'0'+i)];
    }
  }
  cout << res << endl;

  
  


  return 0;
}


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

using lli = long long int;

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

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

int main(void){
    int n;
    cin >> n;
    vector<int> h(n);
    for(int i = 0; i < n; i++){
        cin >> h.at(i);
    }
    int maxv = 0;
    int c = 0;
    for(int i = 0; i < n; i++){
        if(h.at(i) >= maxv) c++;
        maxv = max(maxv, h.at(i));
    }
    cout << c << endl;
    return 0;
}


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

int n,k,i,j;
char a[1000][1000],sum;

int main(){
	cin>>n>>k;
	for(i=1;i<=n;i++){
		for(j=1;j<=k;j++){
			cin>>a[i][j];
		}
	}
	for(i=1;i<=n;i++){
		for(j=1;j<=k;j++){
			if(a[i][j]=='.'){
				sum='0';
				if(a[i][j+1]=='#'){
				sum++;
				}
				if(a[i+1][j+1]=='#'){
				sum++;
				}
				if(a[i][j-1]=='#'){
				sum++;
				}
				if(a[i-1][j-1]=='#'){
				sum++;
				}
				if(a[i-1][j]=='#'){
				sum++;
				}
				if(a[i+1][j-1]=='#'){
				sum++;
				}
				if(a[i-1][j+1]=='#'){
				sum++;
				}
				if(a[i+1][j]=='#'){
				sum++;
				}
				a[i][j]=sum;
			}
		}
	}
	for(i=1;i<=n;i++){
		for(j=1;j<=k;j++){
			cout<<a[i][j];
		}
        cout<<endl;
	}
}


Measured memory_bytes: 3692
#include<iostream>
#include<string.h>
using namespace std;
int main(){
  int x=0,max=0,tmp=0;
  int n;
  char s[n];

  cin>>n;
  cin>>s;
  for(int i=0;i<n;i++){
    if(s[i]=='I')x++;
    else if(s[i]=='D')x--;
    tmp=x;
    if(max<tmp)max=tmp;
  }
  cout<<max;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int base[65],a[205];char s[205];
bool insert(int x){
	for(int i=64;i>=0;--i)
		if((x>>i)&1){
			if(!base[i]) return base[i]=x,1;
			x^=base[i];
		}
	return 0;
}
bool solve(int n){
	memset(base,0,sizeof(base));
	for(int i=1;i<=n;++i)
		cin>>a[i];
	cin>>(s+1);
	for(int i=n;i>=1;--i)
		if(insert(a[i]) && s[i]=='1') return 1;
	return 0;
}
signed main(){
	int T,n;
	cin>>T;
	while(T--){
		cin>>n;
		cout<<solve(n)<<endl;
	}
	return 0;
}

Measured memory_bytes: 3552
s = int(input())
k = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(k[s-1])


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

using namespace std;

int main() {
  string S;
  
  cin >> S;
  
  int ans = 0;
  
  if (S[0] == 'R' || S[1] == 'R' || S[2] == 'R') {
    ans = 1;
  }
  
  if ((S[0] == 'R' && S[1] == 'R') || (S[1] == 'R' && S[2] == 'R')) {
    ans = 2;
  }
  
  if (S[0] == 'R' && S[1] == 'R' && S[2] == 'R') {
    ans = 3;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

int main(){
  int n;
  cin >> n;
  vector<ll> v(n);
  for(int i=0;i<n;i++){
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  ll x, count=1, ans=0;
  x=v[0];
  for(int i=1;i<n;i++){
    if (v[i] == x){
      count++;
    }else{
      if (count > x){
        ans+=count-x;
      }else if (count < x){
        ans+=count;
      }
      x=v[i];
      count=1;
    }
  }
  if (count > x){
    ans+=count-x;
  }else if(count < x){
    ans+=count;
  }
  cout << ans << endl;
  return 0;
}

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

int n, input_data;

int GCD(int a, int b){
	if(a < b) swap(a, b);
	if(b == 0) return a;
	return GCD(b, a % b);
}

int main(void){
	scanf("%d", &n);
	int least_common_multiple = 1;
	for(int i = 1; i <= n; i++){
		scanf("%d", &input_data);
		least_common_multiple = least_common_multiple * input_data / GCD(least_common_multiple, input_data);
	}
	printf("%d\n", least_common_multiple);
	return 0;
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL);
  int n;
  cin >> n;
  vector<int> m(3, 0);
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    int cnt = 0;
    while (x%2 == 0) {cnt++; x >>= 1;}
    if (cnt >= 2) m[2]++;
    else m[cnt]++;
  }
  if (m[0] <= m[2]) cout << "Yes\n";
  else if (m[0] == m[2] +1 and m[1] == 0) cout << "Yes\n";
  else cout << "No\n";
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    string S;
    cin >> S;
    string sub = "keyence";
    if(S == sub){
        cout << "YES" << endl;
        return 0;
    }
    for(int i = 0;i <= 7;i++){
        string ss = S;
        //cout << i << " " << i - 7 + S.size() << endl;
        ss.erase(ss.begin() + i,ss.begin() + i - 7 + S.size());
        //string ss = S.substr(0,i) + S.substr(S.size() - i - 7);
        //cout << ss << endl;
        if(ss == sub){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define repi(i, a, b) for (int i = (a); i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))

using namespace std;
using i32 = long long;
using u32 = unsigned long long;
using i64 = long long;
using u64 = unsigned long long;
using f64 = double;
using vi32 = vector<i32>;
using vu32 = vector<u32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf64 = vector<f64>;
using vstr = vector<string>;
using vvi32 = vector<vi32>;
using vvu32 = vector<vu32>;
using vvi64 = vector<vi64>;
using vvu64 = vector<vu64>;
using vvf64 = vector<vf64>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

i64 dp[100010];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  int n;
  cin >> n;
  vi32 h(n + 1);
  reps(i, n) cin >> h[i];
  dp[1] = 0;
  reps(i, n - 1) dp[i + 1] = 1e18;
  reps(i, n - 1) {
    amin(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]));
    amin(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]));
  }
  cout << dp[n] << endl;
  return 0;
}


Measured memory_bytes: 1792
import sys
def main():
    N=int(sys.stdin.readline())
    p=[float(x) for x in sys.stdin.readline().split()]
    dp=[0 for _ in range(N+1)]
    dp[0]=1.0
    for i in range(1,N+1):
        for j in range(i,0,-1):dp[j]=dp[j-1]*p[i-1]+dp[j]*(1-p[i-1])
        dp[0]=dp[0]*(1-p[i-1])
    print(sum(dp[N//2+1:]))
if __name__=='__main__':main()


Measured memory_bytes: 69128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
typedef complex<double> Point;
#define X real()
#define Y imag()
const double EPS = 1e-9;
#define EQ(n,m) (abs((n)-(m)) < EPS)

// ?????????dot(a,b) = |a||b|cos??
double dot(Point a, Point b) {
  return a.X*b.X + a.Y*b.Y;
}

// ?????????cross(a,b) = |a||b|sin??
double cross(Point a, Point b) {
  return a.X*b.Y - a.Y*b.X;
}

// ??????????????????
int ccw(Point a, Point b, Point c) {
  b -= a;  c -= a;
  if (cross(b,c) >  EPS) return +1;  // counter clockwise
  if (cross(b,c) < -EPS) return -1;  // clockwise
  if (dot(b,c)   < -EPS) return +2;  // c--a--b on line
  if (norm(b) < norm(c)) return -2;  // a--b--c on line or a==b
  return 0;                          // a--c--b on line or a==c or b==c
}

Point proj(Point a1, Point a2, Point p) {
  return a1 + dot(a2-a1, p-a1)/norm(a2-a1) * (a2-a1);
}

bool isecSS(Point a1, Point a2, Point b1, Point b2) {
  return ccw(a1, a2, b1)*ccw(a1, a2, b2) <= 0 &&
         ccw(b1, b2, a1)*ccw(b1, b2, a2) <= 0;
}

// ????????¨???
bool isecSP(Point a1, Point a2, Point b) {
  return !ccw(a1, a2, b);
}

double distSP(Point a1, Point a2, Point p) {
  Point r = proj(a1, a2, p);
  if (isecSP(a1, a2, r)) return abs(r-p);
  return min(abs(a1-p), abs(a2-p));
}

double distSS(Point a1, Point a2, Point b1, Point b2) {
  if (isecSS(a1, a2, b1, b2)) return 0;
  return min(min(distSP(a1, a2, b1), distSP(a1, a2, b2)),
             min(distSP(b1, b2, a1), distSP(b1, b2, a2)));
}

int main(void){
	int q;
	cin>>q;
	rep(i,q){
		double x0,y0,x1,y1,x2,y2,x3,y3;
		cin>>x0>>y0>>x1>>y1>>x2>>y2>>x3>>y3;
		printf("%.9f\n",distSS({x0,y0},{x1,y1},{x2,y2},{x3,y3}));
	}
	return 0;
}

Measured memory_bytes: 3356
#include<bits/stdc++.h>
#define pii pair<int,int>
#define int long long
#define cl(x,y) memset(x,y,sizeof(x))
#define ct cerr<<"Time elapsed:"<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define lson x<<1,l,mid
#define rson x<<1|1,mid+1,r
#define INF 1e18
const int N=1e6+10;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
const double eps=1e-8;
const double pi=acos(-1);
using namespace std;

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n,i,ans=0;
	cin>>n;
	for(i=1;i<=n;i++)
		if(i%3 && i%5)
			ans+=i;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3628
#include "bits/stdc++.h"
using namespace std;

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    if (A + B > C + D){
        puts("Left");
    }else if (A + B < C + D){
        puts("Right");
    }else{
        puts("Balanced");
    }
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong();
    long b = sc.nextLong();
    long k = (a+b)/2;
    if((a+b)%2==0){
      System.out.println(Math.abs(k));
    }else{
      System.out.println("IMPOSSIBLE");
    }
  }
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
using ll = long long; // ll は long long　と同じとする。
int main() {
    string S;
    cin >> S;
    int N = S.size();
    int count = N;
    if(S.at(0) == '0'){
        for(int i = 0; i < N; i+=2){
            if(S.at(i) == '0'){
                count--;
            }
        }
        for(int i = 1; i < N; i+=2){
            if(S.at(i) == '1'){
                count--;
            }
        }
        cout << count << endl;
    }
    else{
        for(int i = 0; i < N; i+=2){
            if(S.at(i) == '1'){
                count--;
            }
        }
        for(int i = 1; i < N; i+=2){
            if(S.at(i) == '0'){
                count--;
            }
        }
        cout << count << endl;
    }
}


Measured memory_bytes: 512
#include <stdio.h>
int main (){        //UMA QUESTÃO SIMPLES E BOA PRA RACIOCINAR SOBRE RESTRIÇÕES.
  int n,min, a[212345], count=1;
  scanf("%d", &n);

  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);

  min = a[0];
  for (int i = 1; i <= n-1; i++) {
    if(a[i] <= min){
      count++;
      min=a[i];
    }
  }

  printf("%d\n", count);

  return 0;
}


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

using namespace std;

string s;
vector <char> q;

int main()
{
	cin >> s;
	q.push_back(s[0]);
	for(int i = 1 ; i < s.size() ; i++)
	{
		if(q[q.size() - 1] == 'S' && s[i] == 'T')
			q.pop_back();
		else
			q.push_back(s[i]);
	}
	cout << q.size();
}


Measured memory_bytes: 772
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;

//typedef modint998244353 mint;

const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;

const ll MAX = 1e9 + 5;

int main() {
	int m;
	cin >> m;
	vector<int> d(m);
	vector<ll> c(m);

	for (int i = 0; i < m; i++) {
		cin >> d[i] >> c[i];
	}

	vector<vector<pll>> dl(10);

	for (int i = 0; i < 10; i++) {
		dl[i].emplace_back(make_pair(i, 0));
	}

	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 60; j++) {

			//cout << j << endl;
			ll num = dl[i][j].first * 2;
			ll cnt = dl[i][j].second * 2 + 1;
			

			if (num >= 10) {
				cnt++;
				num = num % 10 + 1;
			}
			dl[i].emplace_back(make_pair(num, cnt));
		}
		//cout << i << endl;
	}

	/*
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 60; j++) {
			cout << dl[i][j].first << " ";// << dl[i][j].second << endl;
		}
		cout << endl;
	}
	*/

	ll cnt = 0;
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		int num = 0;
		cnt--;
		for (int b = 0; b < 60; b++) {
			
			if (((c[i] >> b) & 1) == 1) {
				num += dl[d[i]][b].first;
				cnt += dl[d[i]][b].second;
				cnt++;
				//cout << i << " " << dl[d[i]][b].second << " " << dl[d[i]][b].first << endl;
			}
			if (num >= 10) {
				num -= 9;
				cnt++;

			}
		}

		a[i] = num;

	}
	//cout << cnt << endl;
	int num = a[0];
	for (int i = 1; i < m; i++) {
		//cout << a[i] << endl;
		num += a[i];
		cnt++;
		if (num >= 10) {
			num -= 9;
			cnt++;

		}
	}

	cout << cnt << endl;
}

Measured memory_bytes: 6404
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t N, Y;
  cin >> N >> Y;
  for (int64_t i = 0; i <= Y / 10000; ++i) {
    for (int64_t j = 0; j <= (Y - 10000 * i) / 5000; ++j) {
      const int64_t k = N - i - j;
      if (k >= 0) {
        if (10000 * i + 5000 * j + 1000 * k == Y) {
          cout << i << " " << j << " " << k << endl;
          return 0;
        }
      }
    }
  }
  cout << -1 << " " << -1 << " " << -1 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))
#define sz(v) ((LLI)(v).size())

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

const LLI mod = 1e9+7;

LLI dp[110][70000];

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

  int N,K;
  while(cin >> N >> K){

    vector<int> div;
    for(int i=1; i*i<=N; ++i){
      div.push_back(i);
      div.push_back(N/i);
    }
    sort(RALL(div));
    UNIQ(div);

    int m = div.size();

    vector<int> cnt(m);
    
    cnt[0] = 1;
    FOR(i,1,m){
      cnt[i] = N/div[i] - N/div[i-1];
    }
    
    fill_array(dp, 0);

    REP(i,m) dp[1][i] = cnt[i];

    FOR(i,1,K){
      vector<LLI> sum(m+1);
      REP(j,m) sum[j+1] = (sum[j] + dp[i][j]) % mod;
      
      REP(j,m){
	dp[i+1][j] += sum[m-j] * cnt[j] % mod;
      }
    }

    LLI ans = 0;
    REP(i,m) (ans += dp[K][i]) %= mod;

    cout << ans << endl;
  }

  
  return 0;
}


Measured memory_bytes: 61564
N,M = map(int,input().split())
A = list(map(int,input().split()))
L = [list(map(int,input().split())) for i in range(M)]

P = sorted(([[1,A[i]] for i in range(N)] + L),key=lambda x: x[1],reverse=True)

ans = 0
rest = N

for cost,value in P :
    K = min(cost, rest)
    K = max(0,K)
    ans += K * value
    rest -= cost

print(ans)


Measured memory_bytes: 44736
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int fb=-1;
	long long c = 0;
	for(int i=0;i<s.length();i++)
	{
			if(s[i]=='B'&&fb==-1)
				fb=i;
			else if(s[i]=='W'&&fb!=-1)
			{
				c = c + i-fb;
				fb++; 
			}

	}
	cout<<c<<"\n";
}

Measured memory_bytes: 3772
#include <cmath>
#include <queue>
#include <cstdio>
#include <iomanip>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 100010
#define ll long long
using namespace std;
inline ll read() 
{ 
    ll x=0,f=1;char ch=getchar(); 
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} 
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} 
    return x*f; 
}
ll cnt,n;
ll h[51];
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
	h[i]=read();
	while(1)
	{
		ll mx=0,mxid=0,sec=100000000000ll;
		for(int i=1;i<=n;i++)
		if(h[i]>mx)mx=h[i],mxid=i;
		for(int i=1;i<=n;i++)
		if(h[i]!=mx)sec=min(sec,h[i]);
		ll tmp=(mx-sec)/(n);
		if(tmp<=0)break;
		cnt+=tmp;
		for(int i=1;i<=n;i++)
		if(i!=mxid)h[i]+=tmp;
		h[mxid]-=tmp*n;
	}
	while(1)
	{
		int pd=0;
		for(int i=1;i<=n;i++)
		if(h[i]>=n){pd=1;break;}
		if(pd==0)break;
		ll mx=0,mxid=0;
		for(int i=1;i<=n;i++)
		if(h[i]>mx)mx=h[i],mxid=i;
		ll tmp=mx/n;
	 	cnt+=tmp;
		for(int i=1;i<=n;i++)
		if(i!=mxid)h[i]+=tmp;
		h[mxid]-=tmp*n;
	}
	printf("%lld\n",cnt);
}
/*
500000000000000000
*/

Measured memory_bytes: 256
import java.util.ArrayList;
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());
        ArrayList<Integer> l = new ArrayList<>();
        for(int i = 0; i < N;i++){
            l.add(Integer.parseInt(sc.next()));
        }
        int previous = Integer.MIN_VALUE;
        for(Integer now : l){
            if(previous <= now - 1){
                previous = now - 1;
            }else if(previous <= now){
                previous = now;
            }else{
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
    }
}

Measured memory_bytes: 48520
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (lli i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

lli n;
int main() {
  cin >> n;
  lli m = n / 2 * 2;
  vector<pair<lli, lli>> e;
  for (lli i=1; i<=m; ++i) {
    for (lli j=1; j<=m; ++j) {
      if (i != j && j != m+1-i && i < j) e.emplace_back(i, j);
    }
  }
  if (n % 2 == 1) {
    for (lli i=1; i<=n-1; ++i) {
      e.emplace_back(i, n);
    }
  }
  cout << e.size() << '\n';
  for (auto& p : e) {
    cout << p.first << ' ' << p.second << '\n';
  }
  return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	while(1){
        int a[10] = {0},b[10] = {0};
        int c,d;
        cin >> c >> d;
        if(c == 0 && d == 0) break;
        a[0] = c / 1000;
        a[1] = c / 100 - a[0]*10;
        a[2] = c / 10 - a[0]*100-a[1]*10;
        a[3] = c -a[0]*1000 - a[1]*100 - a[2]*10;
        b[0] = d / 1000;
        b[1] = d / 100 - b[0]*10;
        b[2] = d / 10 - b[0]*100-b[1]*10;
        b[3] = d -b[0]*1000 - b[1]*100 - b[2]*10;
        int hit = 0;
        int blow = 0;
        for(int i = 0; i < 4; i++){
            for(int j = 0; j < 4; j++){
                if(a[i] == b[j]){
                    if(i == j){
                        hit++;
                    }
                    else blow++;
                }
            }
        }
        cout << hit << " " << blow << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
/**
 * @author      : omgursocute
 * @created     : 12/02/2020
 * @task        : C
 */

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main() {
	// freopen("C.inp", "r", stdin);
	// freopen("C.out", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	
	const int N = 1e9+1;
	int n;
	cin >> n;
	bitset<N> bs;
	string res = "YES";
	while(n--) {
		ll x;
		cin >> x;
		if(bs[x]) res = "NO";
		bs[x] = 1;
	}
	cout << res;

	return 0;
}



Measured memory_bytes: 122748
(defun main ()
  (let* ((n (read))
         (m (read))
         (ans 0))
    (dotimes (i m)
      (setf ans (+ ans (read))))
    (if (< n ans)
        (return-from main -1)
        (setf ans (- n ans)))
    ans))

(format t "~d~%" (main))


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

using namespace std;

typedef long long ll;
typedef vector<ll> v1;

const ll mod = 1000000007;

v1 a[128];
v1 b[128];
ll checked[128];
string s,t;

int main(){
  cin >> s >> t;
  for(ll i = 0;i < s.size();i++){
    a[s[i]].push_back(i);
    b[t[i]].push_back(i);
  }
  for(ll i = 0;i < s.size();i++){
    if(checked[s[i]] == 0){
      checked[s[i]] = 1;
      if(a[s[i]] != b[t[i]]){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 4744
#include <iostream>

using namespace std;

void solve()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		int K, P;
		cin >> K >> P;
		if (K % P ==0)
		{
			cout << P << endl;
		}
		else
		{
			cout << K % P << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1160