akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		int k = saori.saori_hayami();
		
		int[] p = new int[n];
		
		int sum = 0;
		int max = 0;
		for(int i = 0 ; i < n ; i++ ) {
			p[i] = saori.saori_hayami();
			sum += p[i];
			if ( i >= k ) {
				sum -= p[i-k];
			}
			if ( sum > max ) {
				max = sum;
			}
		}
		System.out.println( ((double)max + (double)k)/2f );
		
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 35312
#include <stdio.h>
#define NUM 100000
int pare[NUM];
int rank[NUM];
int size[NUM];


void init(int n){
	for(int i=0;i<n;i++){
		pare[i]=i;
		rank[i]=0;
		size[i]=1;
	}
}

int find(int x){
	if(pare[x]==x)return x;
	return pare[x] = find(pare[x]);
}

void unite(int x,int y){
	x = find(x);
	y = find(y);
	int cx = size[x];
	int cy = size[y];
	if(x==y)return;
	size[x] = size[y] = cx+cy;
	if(rank[x] < rank[y]){
		pare[x]=y;
	}else{
		pare[y] = x;
		if(rank[x] == rank[y])rank[x]++;
	}
}

int same(int x,int y){
	return find(x)==find(y)?1:0;
}

int count(int x){
	return size[find(x)];
}


int main(void){
	int n,m,i;
	scanf("%d%d",&n,&m);
	int a[m],b[m];
	long long ans[NUM]={0};
	for(i=0;i<m;i++){
		scanf("%d%d",&a[i],&b[i]);
		a[i]--,b[i]--;
	}
	ans[m-1] = (long long)n*(n-1)/2;
	init(n);


	for(i=m-2;i>=0;i--){
		if(same(a[i+1],b[i+1])){
			ans[i] = ans[i+1];
		}else{
			ans[i] = ans[i+1] - (long long)count(a[i+1])*count(b[i+1]);
			unite(a[i+1],b[i+1]);
		}
	}
	for(i=0;i<m;i++)printf("%lld\n",ans[i]);
	
	return 0;
}

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

int main() {
	int n;
  	cin >> n;
  	int r = 0;
  	for (int i = 1; i <= n; i++) {
     	int x;
      	cin >> x;
      	if ((x & 1) && (i & 1))
        	r++;
    }
  	cout << r;
}


Measured memory_bytes: 3588
package main

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

const maxBuf = 200100

const debug = false

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

func init() {
	if debug {
		testFile, err := os.Open("./test/sample-1.in")
		if err == nil {
			sc = bufio.NewScanner(testFile)
		}

	}
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBuf)
}

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

func readInt() int {
	sc.Scan()
	r, _ := strconv.Atoi(sc.Text())
	return r
}

func readFloat64() float64 {
	sc.Scan()
	r, _ := strconv.ParseFloat(sc.Text(), 64)
	return r
}

/* #### main #### */
func main() {
	N := readInt()
	D := readInt()
	x := make([]int, N)
	y := make([]int, N)

	for i := 0; i < N; i++ {
		x[i] = readInt()
		y[i] = readInt()
	}

	ans := 0
	for i := 0; i < N; i++ {
		if math.Sqrt(float64(x[i]*x[i]+y[i]*y[i])) <= float64(D) {
			ans++
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 7812
//Tanzim bin nasir
#include<bits/stdc++.h>
typedef long long ll;
#define ff first
#define ss second
using namespace std;
void fast()
{
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
}
ll gcd(ll a,ll b)
{
    if(b==0)
    return a;
    else
    gcd(b,a%b);
}
ll lcd(ll a,ll b)
{
    return (a*b)/gcd(a,b);
}
int main()
{
    int n,ans=1,mn,temp;
    cin>>n>>mn;
    for(int i=1;i<n;i++)
    {
        cin>>temp;
        if(temp<=mn)
        {
            mn=temp;
            ++ans;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3508
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int a[n],b;
    for(int i=0;i<n;i++){
        cin>>b;
        if(i==0){
            a[i]=b;
        }
        else{
            a[i]=a[i-1]+b;
        }
    }
    int ans=1e9;
    for(int i=0;i<n-1;i++){
        ans=min(ans,abs(a[n-1]-a[i]-a[i]));
    }
    cout << ans<<endl;

    return 0;
}



Measured memory_bytes: 256
N = int(input())
As = list(map(int, input().split()))

sm = []
tmp = 0
for a in As:
  tmp += a
  sm.append(tmp)
  
rlt = sum(map(abs, As))
for i in range(N-1):
  rlt = min(rlt, abs(2*sm[i]-sm[-1]))
  
print(rlt)

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

int main()
{
    int k,x,l,r;
    cin >> k>>x;
    l = max(x-k+1,-1000000);
    r = min(x+k-1,1000000);
    for(int i=l;i<=r;i++){
        cout << i << ' ';
    }
    cout << endl;
    return 0;
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

#define M_PI 3.141592653589793238462643383279

li n;
PI xy[111];

int main() {
    cin >> n;
    rin{
        cin >> xy[i].F >> xy[i].S;
    }

    li lim = 100000;
    double res = 0.0;
    rep(i, lim) {
        double rad = M_PI * 2.0 * i / lim;
        PI tres = {0, 0};

        pair<double, double> dir = {cos(rad), sin(rad)};

        rep(j, n) {
            double ip = dir.F * xy[j].F + dir.S * xy[j].S;
            if (ip >= -EPS) {
                tres.F += xy[j].F;
                tres.S += xy[j].S;
            }
        }

        res = max(res, hypot(tres.F, tres.S));
    }


    printf("%.12f\n", res);

    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const ll INF = 1LL << 50;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
///////////////////////////////////////

int main() {
	int H, W; cin >> H >> W;
	char C[51][51];
	ll d[51][51];
	int bcount = 0;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			cin >> C[i][j];
			if (C[i][j] == '#')bcount++;
			d[i][j] = INF;
		}
	}
	queue<pii>Q;
	Q.push({ 0,0 });
	d[0][0] = 0;
	while (!Q.empty()) {
		pii P = Q.front();
		int y = P.first;
		int x = P.second;
		Q.pop();
		for (int i = 0; i < 4; ++i) {
			int ny = y + dy[i];
			int nx = x + dx[i];
			if (ny >= 0 && ny < H&&nx >= 0 && nx < W&&C[ny][nx] == '.'&&d[ny][nx]==INF) {
				Q.push({ ny,nx });
				d[ny][nx] = d[y][x] + 1;
			}
		}
	}
	if (d[H - 1][W - 1] == INF) {
		cout << -1 << endl;
	}
	else {
		cout << W * H - d[H - 1][W - 1] - 1 - bcount << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import heapq as pq
N,K = map(int,input().split(" "))
priority_que = []
t,d= [0]*N,[0]*N
sushi_max = [-1] * N
cnt = [0] * N

for i in range(N):
    t[i],d[i] = map(int,input().split(" "))
    sushi_max[t[i]-1] = max(sushi_max[t[i]-1],d[i])

t ,d= zip(*sorted(zip(t,d),reverse=True,key=lambda x: x[1]))
ans = 0
for i in range(K):
    cnt[t[i]-1] += 1
    sushi_max[t[i]-1] = -1
    pq.heappush(priority_que,(d[i],t[i]))
    ans += d[i]

sz = len(list(filter(lambda x: x > 0,cnt)))
ans += (sz * sz)

sushi_max = sorted([ (val,idx) for idx,val in enumerate(sushi_max) ],reverse=True,key=lambda x:x[0])
idx = 0
cur = ans
while len(priority_que) > 0 and sushi_max[idx][0] != -1:
    minValue,minIdx = pq.heappop(priority_que)
    if cnt[minIdx-1] == 1:
        continue
    cur += ( (sz+1)*(sz+1) - (sz*sz) + sushi_max[idx][0] - minValue )
    cnt[minIdx-1] -= 1
    sz += 1
    idx += 1
    ans = max(cur,ans)
print(ans)


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

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int main(void){
	int n,i,j;
	bool flag,ans=false;
	string s,t="keyence";
	cin >> s;
	n = s.l_ength();
	for(i=0; i<=7; ++i){
		flag = true;
		for(j=0; j<i; ++j){
			if(s[j]!=t[j]){
				flag = false;
				break;
			}
		}
		if(!flag){
			continue;
		}
		for(j=i; j<7; ++j){
			if(s[n-7+j]!=t[j]){
				flag = false;
				break;
			}
		}
		if(!flag){
			continue;
		}
		ans = true;
		break;
	}
	cout << ((ans)?"YES":"NO") << endl;
	return 0;
}


Measured memory_bytes: 256
use std::collections::HashSet;
use whiteread::parse_line;

fn main() {
    let s: String = parse_line().unwrap();
    let s = s.as_str();
    let mut set = HashSet::new();
    for c in s.chars() {
        if !set.insert(c) {
            println!("no");
            return;
        }
    }
    println!("yes");
}


Measured memory_bytes: 2140
//
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <array>
#include <numeric>
#include <functional>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<utility>
#include<complex>

using namespace std;

#define REP(i,m,n) for(int i=m;i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef pair<int, int> pii;

const ll inf = INT_MAX;
const double eps = 1e-10;
const double pi = acos(-1.0);
const int di[][2] = {{1,0},{0,1},{-1,0},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1}};

int main(){

	int a,b,c;
	cin >> a >> b >>c;
	if(a == b+c || b == c+a || c == a+b) printf("Yes\n");
	else printf("No\n");

	return 0;
}


Measured memory_bytes: 888
import java.util.Scanner;

import com.sun.org.apache.xpath.internal.operations.Equals;

class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);

		String S = scan.next();
		
		if(S.equals("SUN")){
			System.out.println("7");
		}else if(S.equals("MON")){
			System.out.println("6");
		}else if(S.equals("TUE")){
			System.out.println("5");
		}else if(S.equals("WED")){
			System.out.println("4");
		}else if(S.equals("THU")){
			System.out.println("3");
		}else if(S.equals("FRI")){
			System.out.println("2");
		}else if(S.equals("SAT")){
			System.out.println("1");
		}
		

	}

}

Measured memory_bytes: 23120
k = int(input())
a = list(map(int, input().split()))

l = -1
r = 10**18
while r - l > 1:
    m = l + (r-l)//2
    n = m
    for i in range(k):
        n = n//a[i] * a[i]
    if n >= 2:
        r = m
    else:
        l = m

ansl = r
l = -1
r = 10**18
while r - l > 1:
    m = l + (r-l)//2
    n = m
    for i in range(k):
        n = n//a[i] * a[i]
    if n <= 2:
        l = m
    else:
        r = m

ansr = l

if ansl <= ansr:
    print(ansl, ansr)
else:
    print(-1)


Measured memory_bytes: 63856
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int K, X; cin >> K >> X;
    if(500 * K >= X) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
s = input()

index_A = float('inf')
index_Z = -1

for i in range(len(s)):
    if s[i] == 'A':
        if i < index_A:
            index_A = i
    elif s[i] == 'Z':
        if i > index_Z:
            index_Z = i

print(index_Z - index_A + 1)

Measured memory_bytes: 3512
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
typedef tuple<ll, ll, ll> T;

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

int digitsum(int n){
    int ans=0;
    while(n>0){
        ans += n%10;
        n/=10;
    }
    return ans;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int ans=INF;
    for(int a=1;a<n;a++){
        int b=n-a;
        ans = min(ans,digitsum(a)+digitsum(b));
    }
    cout<<ans<<endl;

}

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

int main()
{
    int n,a;
    map<int,int>mp;
    set<int>s;
    cin>>n;

    for(int i=0; i<n; i++)
    {
        cin>>a;
        s.insert(a);
        mp[a]++;
    }
    a=s.size();
    for(int i:s)
    {
        if(mp[i]%2==0)
         a--;
    }
    cout<<a;

}


Measured memory_bytes: 12932
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		  Scanner sc = new Scanner(System.in);
		  int a = sc.nextInt();
		  int b = sc.nextInt();
		  b = b * 2;
		  if (a >= b) {
			  System.out.println(a - b);
		  }
		  else if (a <= b) {
			  System.out.println(0);
		  }
	}		
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
const int mod = 1e9 + 7;
const int INF = 1e9;
const double pi = acos(-1.0);
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
int main(){
    int x, y;
    cin >> x >> y;
    bool ans = true;
    if(y % 2 == 1)ans = false;
    if(2*x < y/2 || y/2 < x)ans = false;
    cout << ((ans)?"Yes":"No") << endl;
    return 0;
}  

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18

using namespace std;


ll keta(ll a){
  if (a == 0)
    return 0;
  else
    1 + keta(a/10);
}

ll sentou(ll a){
  if (a < 10)
    return sentou(a / 10);
}

ll hoge(ll a){
  ll ta = a - sentou(a)*pow(10, keta(a) - 1);
  if (sentou(a) - sentou(ta) >= 2)
//    return dp[sentou(a)][keta(a)];
    ;
  if (sentou(a) - sentou(ta) <= -2)
    return 0;
  if (sentou(a) - sentou(ta) == 1){
    ;
  }
}

int main(void){
  ll k;
  cin >> k;
  
  vector<vector<ll>> dp(10, vector<ll>(15, 0));
  
  for (int i = 0; i < 10; i++){
    dp[i][1] = 1;
  }
  for (int j = 2; j < 15; j++){
    for (int i = 0; i < 10; i++){
      if (i == 0)
        dp[0][j] = dp[0][j-1] + dp[1][j-1];
      else if (i == 9){
        dp[9][j] = dp[9][j-1] + dp[8][j-1];
      }
      else 
        dp[i][j] = dp[i-1][j-1] + dp[i][j-1] + dp[i+1][j-1];
    }
  }
  /*
  ll l = 0, r = 1e12, m;
  while (l + 1 < r){
    m = (l + r)/2;

    ll res = 0;
    for (int j = 0; j < keta(m); j++){
      for (int i = 1; i < 10; i++){
        res += dp[i][j];
      }
    }
    for (int i = 1; i < sentou(m); i++){
      res += dp[i][keta(m)];
    }

    res += hoge(m);

    if (res >= k)
      r = m;
    else
      l = m;
  }
  */

  ll num = 1;
  int a = 1, b = 1;
  while (num < k){
    if (a == 9){
      b++;
      a = 1;
    }
    else 
      a++;
    num += dp[a][b];
  }

  string res = "";


  num -= dp[a][b];
  b--;
  res += {a + '0'};
  while (b > 0){
    if (a == 0){
      if (num + dp[0][b] >= k){
        res += {'0'};
        a = 0;
      }
      else {
        num += dp[0][b];
        res += {'1'};
      }
      b--;
    }
    else if (a == 9){
      if (num + dp[8][b] >= k){
        res += {'8'};
        a = 8;
      }
      else {
        num += dp[8][b];
        res += {'9'};
      }
      b--;
    }
    else {
      if (num + dp[a-1][b] >= k){
        res += {a - 1 + '0'};
        a = a-1;
      }
      else if (num + dp[a-1][b] + dp[a][b] >= k){
        num += dp[a-1][b];
        res += {a + '0'};
      }
      else {
        num += dp[a-1][b] + dp[a][b];
        res += {a + 1 + '0'};
        a = a + 1;
      }
      b--;
    }
  }


  cout << res << endl;


  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int ans = 0;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		for(int i = 0;i<n;i++) {
			System.out.print("ACL");
		}
		
		
	}
}


Measured memory_bytes: 35728
// failed to generate code

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

double dp[3001][6001] = {};
int main(){	
    ios::sync_with_stdio(false);
    int N;
    cin >> N;

    vector<double> p(N);
    for(int i = 0 ; i < p.size() ; i++){
        cin >> p[i];
    }


    dp[0][3000] = 1.0;

    for(int i = 0 ; i < p.size() ; i++){
        for(int j = 0 ; j <= 6000 ; j++){
           if( dp[i][j] != 0.0 ){
                dp[i+1][j+1] += dp[i][j] * p[i];
                dp[i+1][j-1] += dp[i][j] * (1-p[i]);
           }

        }
    }


    double tot = 0;
    for(int i = 3001 ; i <= 6000 ; i++)
        tot += dp[N][i];

    printf("%.15lf\n", tot);



}


Measured memory_bytes: 138752
import sys
import math

def decide_move(x,y,tile,check):
	if tile == '<':
		y -= 1
		check[x][y] += 1
		return x,y,check
	elif tile == '>':
		y += 1
		check[x][y] += 1
		return x,y,check
	elif tile == '^':
		x -= 1
		check[x][y] += 1
		return x,y,check
	else:
		x += 1
		check[x][y] += 1
		return x,y,check


while True:
	h,w = map(int,input().split())
	if h == 0:
		break
	tile_map = []
	for i in range(h):
		tile_map.append(input())
	check =[[0 for i in range(w)]for j in range(h)]
	check[0][0] = 1
	x = 0
	y = 0
	status = 0

	while True:
		if tile_map[x][y] == '.':
			status = 1
			print(y,x)
			break
		x,y,check = decide_move(x,y,tile_map[x][y],check)
		if check[x][y] > 1:
			status = 1
			print('LOOP')
			break

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

int main() {
  long long x,c;
  cin >> x;
  c = x/11*2;
  if(x%11 != 0){
    if(x%11 < 7) c++;
    else c += 2;
  }
  cout << c << endl;
}


Measured memory_bytes: 256
// Author : Nachiket Kanore
// Institute : PICT, Pune

/* It does not matter how slowly you go as long as you do not stop.*/

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define endl '\n'
#define rep(x,s,e) for(int x=s;x<=(e);x++)
#define repn for(int x=0;x<n;x++)
#define rep1n for(int x=1;x<=n;x++)
#define rep1m for(int y=1;y<=m;y++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define precise(x) cout << fixed << setprecision(x)
#define bits(x) __builtin_popcount(x)
#define pb push_back
#define mp make_pair
#define test int t; cin>>t; while(t--)
#define FAST                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)

typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef pair<int,int> pii;


void __print(int x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}


template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define see(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define see(x...)
#endif

const int inf = 1e18;
const int N = 1005;



int32_t main(){
    FAST;

    int n;  cin >> n;
    string s;   cin >> s;
    if(n < 3200)
        cout << "red" << endl;
    else cout << s << endl;

    return 0;
}




Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int t;
    scanf("%d",&t);
    int c=1;
    while(t!=0)
    {
        int n;
        scanf("%d",&n);
        if(n%2==0)
        {
            if((n%3)&&(n%5))
            {
                c=0;
                break;
            }
        }
        t--;
    }
    if(c==0)
    {
       printf("DENIED");
    }
    else
    {
        printf("APPROVED");
    }

    return 0;
}


Measured memory_bytes: 128
using LIB;
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;

class Program
{
    public static IO IO = new IO();
    static void Main(string[] args)
    {
        int n = IO.INT();
        HashSet<string> dic = new HashSet<string>();

        for (int i = 0; i < n; i++)
        {
            string[] b = IO.STRING(' ');
            switch (b[0])
            {
                case "insert":
                    dic.Add(b[1]);
                    break;
                case "find":
                    if (dic.Contains(b[1])) { IO.WRITE("yes"); } else { IO.WRITE("no"); }
                    break;
            }
        }
        IO.FLUSH();
    }
}

namespace LIB
{
    public class IO
    {
        private const int WMAX = 1000;
        private StringBuilder S = new StringBuilder();
        private T R<T>(Func<string, T> f) { return f(Console.ReadLine()); }
        private T[] R<T>(Func<string, T> f, char c) { return STRING().Split(c).Select(f).ToArray(); }
        private T[] R<T>(Func<string, T> f, int l) { T[] r = new T[l]; for (int i = 0; i < l; i++) { r[i] = R(f); } return r; }
        private T[][] R<T>(Func<string, T> f, int l, char c) { T[][] r = new T[l][]; for (int i = 0; i < l; i++) { r[i] = R<T>(f, c); } return r; }
        private void W<T>(Func<T, string> f, T v, bool lf = true) { S.Append(f(v)); if (lf == true) { S.Append('\n'); } if (S.Length >= WMAX) { FLUSH(); } }
        public string STRING() { return R(s => s); }
        public string[] STRING(char c) { return R(s => s, c); }
        public string[] STRING(int l) { return R(s => s, l); }
        public string[][] STRING(int l, char c) { return R(s => s, l, c); }
        public int INT() { return R(int.Parse); }
        public int[] INT(char c) { return R(int.Parse, c); }
        public int[] INT(int l) { return R(int.Parse, l); }
        public int[][] INT(int l, char c) { return R(int.Parse, l, c); }
        public long LONG() { return R(long.Parse); }
        public long[] LONG(char c) { return R(long.Parse, c); }
        public long[] LONG(int l) { return R(long.Parse, l); }
        public long[][] LONG(int l, char c) { return R(long.Parse, l, c); }
        public double DOUBLE() { return R(double.Parse); }
        public double[] DOUBLE(char c) { return R(double.Parse, c); }
        public double[] DOUBLE(int l) { return R(double.Parse, l); }
        public double[][] DOUBLE(int l, char c) { return R(double.Parse, l, c); }
        public void WRITE(string s, bool lf = true) { W(v => v, s, lf); }
        public void WRITE(int s, bool lf = true) { W(v => v.ToString(), s, lf); }
        public void WRITE(long s, bool lf = true) { W(v => v.ToString(), s, lf); }
        public void WRITE(double s, bool lf = true) { W(v => v.ToString(), s, lf); }
        public void FLUSH() { Console.Write(S); S.Length = 0; }
    }
}

Measured memory_bytes: 40344
a, b = map(int, input().split())
if a * b <= 0:
    print('Zero')#途中に0を挟む
elif a > 0:
    print('Positive')#積は正
elif (b - a + 1) % 2 == 1:
    print('Negative')#a,b区間は全て負の値で、その個数は奇数なので、積は負
else:
    print('Positive')#積は正

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

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int INF = int (1e9) + int (1e5);
const ll INFL = ll(2e18) + ll(1e10);
const ui MOD = 1E9 + 7;
const double EPS = 1e-9;
#define FOR(i,n) for (int i=0;i<(n);++i)
#define ROF(i,x) for(int i = (x) ; i >= 0 ; --i)
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ODD(x) (((x)&1)==0?(0):(1))
#define sign(x) ((x > 0) - (x < 0))
std::mt19937_64  generator(std::chrono::system_clock::now().time_since_epoch().count());

inline ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a, ll b) { return a ? gcd(b%a, a): b; }
ll lcm(ll a, ll b) { return a / gcd(a,b) * b; }


void READ(){
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef _DEBUG
    freopen ("in.txt", "r", stdin);
#endif
}

vector<int> primes;
void erat(unsigned int limit) {
    vector<bool> prime(limit + 1, true);
    const unsigned int n = sqrt(limit);
    unsigned int i, j;
    primes.push_back(2);
    for(i = 3; i <= n; i += 2) {
        if(prime[i]) {for(j = i * i; j <= limit; j += 2*i) prime[j] = false;}
    }
    for(i = 3; i <= limit; i += 2) {if(prime[i]) primes.push_back(i);}
}


vector<int> primes_in_range(int n,int m){
    if (n==1) ++n;
    /// devuelve los primos en el intervalo [n,m]
    int m1=m-n+1;
    vector<bool> s(m1,true);
    for (int i : primes){
        int i2 = i*i;
        int start;
        if (i2>=n){
            start= i2-n;
        }else{
            int mm=n%i;
            if (mm<0) mm += i;
            start = mm != 0 ? i-mm : 0;
        }
        for (int j=start;j<m1; j += i) s[j]=false;
    }
    vector<int> ret;
    for(int i = 0; i < m1; ++i) {
        if(s[i]) ret.push_back(i+n);
    }
    return ret;
}

map<ll, ll> fact(ll n) { //O (cant primos)
    map<ll, ll> ret;
    int idx=0;
    ll p=primes[0];
    while (p*p<=n) {
        while(!(n % p)) {
            ++ret[p];//divisor found
            n /= p;
        }
        p = primes[++idx];
    }
    if(n > 1) ++ret[n];
    return ret;
}

const int N=1E9;
int main() {
    ll s;cin>>s;
    int x=(N-s%N)%N;
  	int y= (s+x)/N;
    cout << "0 0 " << N << " 1 " << x << " " << y;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <stack>
#include <map>
#include <functional>
#include <queue>
using namespace std;

int64_t min(int64_t a,int64_t b) {
    if (a > b)
    {
        return b ;
    }else
    {
        return a ;
    }
}


int main(){
    int d ;
    cin >> d ;
    vector<int> c (26,0) ;
    for (int i = 0; i < 26; i++)
    {
        cin >> c.at(i) ;
    }
    vector<vector<int> > s(d,vector<int>(26)) ;
    for (int i = 0; i < d; i++)
    {
        for (int j = 0; j < 26 ; j++)
        {
            cin >> s.at(i).at(j) ;
        }
        
    }
    vector<int>ans(0) ;
    vector<int64_t> score(0) ;
    int64_t snow = 0 ;
    vector<int> last(26,-1) ;
    vector<int> judge(26,0) ;
    for (int i = 0; i < d; i++)
    {
        for (int j = 0; j < 26; j++)
        {
            judge.at(j) = c.at(j) * (i - last.at(j)) + s.at(i).at(j) ;
        }
        
        int num = 1 ;
        int temp = judge.at(0) ;
        for (int j = 0; j < 26; j++)
        {
            if (temp < judge.at(j) )
            {
                temp = s.at(i).at(j) ;
                num = j+1 ;
            }
            
        }
        ans.push_back(num) ;
        //snow += s.at(i).at(num-1) ;
        last.at(num-1) = i ;
        for (int j = 0; j < 26; j++)
        {
            snow -= c.at(j) * (i - last.at(j)) ;
        }
        //score.push_back(snow) ;
    }
    for (int i = 0; i < d; i++)
    {
        cout << ans.at(i) << endl ;
    }
    //cout << snow << endl ;

}

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

int main(){
	int m,f,r;
	int x=0;
	
	while(1){
		cin>>m>>f>>r;
		if(m==-1&& f==-1 && r==-1)
			break;

		if(m==-1 || f==-1)
			cout<<"F\n";
		else if(m+f>=80)
			cout<<"A\n";
		else if(m+f>=65 && m+f<80)
			cout<<"B\n";
		else if((m+f>=50 && m+f<65) || (m+f>=30 && m+f<50 && r>=50))
			cout<<"C\n";
		else if(m+f>=30 && m+f<50)
			cout<<"D\n";
		else if(m+f<30 )
			cout<<"F\n";
	}
}
	

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

using namespace std;

int main(){
	int N,min=1000001,sum=0;
	cin>>N;
	int X[N+1];
	for(int i=1;i<=N;i++){
		cin>>X[i];
	}
	for(int p=1;p<=100;p++){
		sum=0;
		for(int i=1;i<=N;i++){
			sum+=(X[i]-p)*(X[i]-p);
		}
		if(sum<min)min=sum;
	}
	cout<<min;
	return 0;
}

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

int main() {
    int N; cin >> N;
    float x;
    string u;

    float cnt = 0;

    for(int i=0; i<N; i++){
        cin >> x >> u;
        if(u == "JPY"){
            cnt += x;
        }
        else{
            cnt += 380000*x;
        }
    }

    cout << cnt << endl;

    

    

    return 0;
}

Measured memory_bytes: 256
import math
n=int(input())
b=n*(n-1)/2
x = [0] * n
y = [0] * n
a=0
for i in range(n):
  x[i], y[i] = map(float, input().split())
for i in range(n-1):
  for j in range(i+1,n):
    a+=((x[i]-x[j])**2+(y[i]-y[j])**2)**(1/2)
print(a/b*(n-1))


Measured memory_bytes: 3064
N = int(input())
A = input().split(" ")
A = [int(i) for i in A]
list = [min(A)]
A = sorted(A)
iii = 0
while True:
    iii += 1
    if A[N-1] % A[N-2] != 0:
        A[N-1] = A[N-1] % A[N-2]
    elif N >= 3 and A[N-1] % A[N-3] != 0:
        A[N-1] = A[N-1] % A[N-3]
    elif N >= 4 and A[N-1] % A[N-4] != 0:
        A[N-1] = A[N-1] % A[N-4]
    elif N >= 5 and A[N-1] % A[N-5] != 0:
        A[N-1] = A[N-1] % A[N-5]
    elif N >= 6 and A[N-1] % A[N-6] != 0:
        A[N-1] = A[N-1] % A[N-6]
    elif N >= 7 and A[N-1] % A[N-7] != 0:
        A[N-1] = A[N-1] % A[N-7]
    elif N >= 8 and A[N-1] % A[N-8] != 0:
        A[N-1] = A[N-1] % A[N-8]
    elif N >= 9 and A[N-1] % A[N-9] != 0:
        A[N-1] = A[N-1] % A[N-9]
    elif N >= 10 and A[N-1] % A[N-10] != 0:
        A[N-1] = A[N-1] % A[N-10]

    A = sorted(A)
    list.append(min(A))
    if iii > 96:
        break       
#print(list)
for i in range(N-1):
    if A[i+1]-A[i] > 0:
        list.append(A[i+1]-A[i])
#print(list)
print(min(list))

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < n; i++)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N;
    cin >> N;

    vector<ll> A(N);
    rep (i, N) {
        cin >> A[i];
    }

    ll count = 0;
    rep (i, N) {
        if (A[i] < 0) {
            count++;
        }
    }

    ll tmp = MOD;
    ll ans = 0;
    rep (i, N) {
        ans += abs(A[i]);
        tmp = min(tmp, abs(A[i]));
    }

    if (count % 2 == 0) {
        cout << ans << endl;
    } else {
        cout << ans - 2*tmp << endl;
    }

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <tuple>

using namespace std;

template <class T>
void print_vec(const vector<T>& v) {

  for (auto t = begin(v); t != end(v);) {
    cout << *t;
    if (++t != end(v)) {
      cout << " ";
    }
  }
  cout << endl;
}

tuple<vector<int>, int> bubbleSort(const vector<int>& a, const int& n) {
  vector<int> ret = a;
  bool flag = true;
  int count = 0;
  while (flag) {
    flag = false;
    for (int j = n-1; j > 0; j--) {
      if (ret[j] < ret[j-1]) {
        swap(ret[j], ret[j-1]);
        count++;
        flag = true;
      }
    }
  }
  return make_tuple(ret, count);
}

int main(int ac, char **av) {
  int n;
  while (cin >> n, n) {
    vector<int> a;
    for (int i = 0; i < n; i++) {
      int x;
      cin >> x;
      a.push_back(x);
    }
    auto ret = bubbleSort(a, n);
    print_vec(get<0>(ret));
    cout << get<1>(ret) << endl;
    n = 0;
  }
  return 0;
}

Measured memory_bytes: 3128
#include <iostream>
using namespace std;
int main() {
  int k;
  cin >> k;
  int x = 0;
  for (int i = 1; i <= k; ++i) {
    x = 10 * x + 7;
    x %= k;
    if (x == 0) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}



Measured memory_bytes: 3600
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 1000100


int main(){
	char a[N + 1];
	int b[N + 1];
	queue<int>q;
	f(i, N + 1)a[i] = 0;
	int n, k;
	int qq;
	int x;
	long long y, z;
	long long s, ans;
	bool v = true;
	ans = 0;
	scanf("%d", &n);
	scanf("%s", a);
	if (a[0] == 'M')b[0] = 1;
	else b[0] = 0;
	f(i, n-1){
		if (a[i + 1] == 'M')b[i + 1] = b[i] + 1;
		else b[i + 1] = b[i];
	}

	scanf("%d", &qq);
	f(qqq, qq){
		scanf("%d", &k);
		s = 0;
		y = 0;
		ans = 0;
		while (!q.empty())q.pop();
		f(i, n){
			if (a[i] == 'D'){
				q.push(i);
				s += b[i];
				y++;
			}
			if (a[i] == 'C'){
				if (!q.empty()){
					x = q.front();
					while ((x + k) <= i){
						q.pop();
						s -= b[x];
						y--;
						if (q.empty())break;
						x = q.front();
					}
				}
				ans += (y*b[i]) - s;
			}
		}
		printf("%lld\n", ans);
	}



	return 0;
}

Measured memory_bytes: 9216
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef complex<double> xy_t;
typedef vector<lint> poly;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

const lint mod = 1e9+7;
const lint INF = mod*mod;
const int MAX =100010;

int main(){
    int n;
    scanf("%d", &n);
    int d[n][n], E[n][n];
    rep(i, n){
        string s;
        cin>>s;
        rep(j, n) d[i][j]=E[i][j]=s[j]-'0';
    }

    rep(i, n){
        rep(j, n) d[i][j]=E[i][j] ? 1 : MAX;
        d[i][i]=0;
    }
    rep(k, n)rep(i, n)rep(j, n) chmin(d[i][j], d[i][k]+d[k][j]);
    int ans=-1;
    rep(i, n)rep(j, n){
        chmax(ans, d[i][j]+1);
        rep(k, n)if(d[i][j]==d[i][k] && E[j][k]){
            printf("-1\n");
            return 0;
        }
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 640
import java.util.*;

class Main{
    public static void main(String[]args){
		Scanner sc = new Scanner(System.in);
		int iin = sc.nextInt();
		int iia = sc.nextInt();
		int iib = sc.nextInt();
        int retint = 0;
        iin++;
        for(int i=1;i<iin;i++){
            int kari = i;
            int kariketa = 0;
            while(true){
                kariketa += kari % 10;
                kari /= 10;
                if(kari == 0){
                    break;
                }
            }
            if(kariketa >= iia && kariketa <= iib){
                retint += i;
            }
        }
		System.out.println(retint);
    }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl "\n"
using namespace std;
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
 
    int x,y;
    cin >> x >> y;
 
    int a=((4*x)-y)/2;
    int b=(y-(2*x))/2;
 
    if ((a<0)||(b<0))
    {
        cout << "No" << endl;
        return 0;
    }
 
    if (((a+b)==x)&&(((2*a)+(4*b))==y))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
 
    return 0;
}

Measured memory_bytes: 3616
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	//数値の入力
		int n = sc.nextInt();
        int count = 0;
        for(int i = 0; i < n+1; i++){
            	count = count+i; 
            }
       System.out.println(count);

}
}

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

#define int long long

int gcd(int a, int b) {
  if (b == 0) return a;
  else if (a < b) return gcd(b, a);
  else return gcd(b, a % b);
}


signed main(void) {
  int num; // num
  num = 0; // count, result
  // num = numeric_limits<int>::min(); // max
  // num = numeric_limits<int>::max(); // min
  int N;
  // int M;
  array<int, 100000> A;
  // string S;
  // string T;

  cin >> N;

  if (N == 1) {
    cout << "Hello World" << endl;
  } else {
    int a, b;
    cin >> a;
    cin >> b;
    cout << a + b << endl;
  }
  
  // cin >> N;
  // for (auto it = A.begin(); it < A.begin() + N; ++it) cin >> *it;

  // for (auto it = A.begin(); it < A.begin() + N; ++it) if (*it % 2 == 0) ++num;

  // cout << num << endl;;
  
  return 0;
}


Measured memory_bytes: 256
N=int(input())
s=list(input() for _ in range(N))
ans=0
count=0
a_count=0
b_count=0
ab_count=0
for i in s:
    ans+=i.count('AB')
    if i[0]=='B'and i[-1]=='A':
        ab_count+=1
    elif i[0]=='B':
        b_count+=1
    elif i[-1]=='A':
        a_count+=1
print(ans+min(a_count,b_count)+ab_count if a_count+b_count!=0 else ans+max(ab_count-1,0))

Measured memory_bytes: 44376
#include <iostream>
#include <string>
#include <vector>
#include <string.h>
#include <algorithm>

using namespace std;


int main(){
  int n,y,Y,x;
  cin >> n >> Y;
  int judge=0;
  for(x=0; x<n+1;x++){
    for(y=0; y<n-x+1;y++){
      if(10000*x + 5000*y + 1000*(n-x-y) == Y && n-x-y>=0){
        judge=1;
        break;
      }
      else if(n-x-y<0) break;
    }
    if(judge==1) break;
    //if(10000*x + 5000*y > Y){
      //break;
    //}
  }
  if(judge == 1){
    cout << x <<" "<<y <<" "<<n-x-y <<" "<< endl;
  }else{
    cout << "-1 -1 -1" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) x.begin(),x.end()
using namespace std;
const int INF = 1e9;

double expectation(int num) {
    int sum = 0;
    for (int i=1; i<=num; ++i) sum += i;
    return (double) sum / (double) num;
}

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

    int n,k;
    cin >> n >> k;
    vector<int> p(n);
    rep (i, n) cin >> p[i];
    vector<int> s(n, 0);
    rep (i, n) s[i+1] = s[i] + p[i]; 
    int m = -INF;
    int pos = -1;
    rep (i, n-k+1) {
        int v = s[k+i]-s[i];
        if (m < v) {
            m = v;
            pos = i;
        }
    }
    double ans=0;
    for (int i=pos; i < pos + k; ++i) {
        ans += expectation(p[i]);
    }
    cout << fixed;
    cout << setprecision(7) << ans << endl;
    return 0;
}

Measured memory_bytes: 4740
#include <cstdio>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; ++i)

int main() {
  int N; scanf("%d", &N);
  std::vector<int> a(N);
  REP(i,N) {
    scanf("%d", &a[i]);
    a[i]--;
  }
  int cur = a[0], cnt = -1;
  REP(i,N) {
    if (cur == 1) {
      cnt = i + 1;
      break;
    }
    cur = a[cur];
  }
  printf("%d\n", cnt);
}

Measured memory_bytes: 640
import java.util.Scanner;

    public class Main {
        public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double r = sc.nextDouble();
        double pi = Math.PI;
        double area =  r*r*pi;
        double length = 2*r*pi;
    System.out.printf("%f %f", area, length);
    }
}


Measured memory_bytes: 28284
N = int(input())
A = list(map(int, input().split()))
A = [0] + A + [0]
total_dist = 0
now = 0
for A_i in A:
    total_dist += abs(A_i - now)
    now = A_i

def solve():
    for i in range(N):
        print(total_dist+abs(A[i] - A[i+2])-abs(A[i]-A[i+1])-abs(A[i+1]-A[i+2]))


solve()

Measured memory_bytes: 14048
N ,q = map(int,input().split())
A = [input() for i in range(N)]

B = []
for raw in A:
    name,time = raw.split()
    B.append({
    "name":name,
    "time":int(time)
    })

total_time = 0
now = 0
while len(B)> 0:
    if B[now]["time"] > q:
        B[now]["time"] = B[now]["time"] - q
        total_time += q
        if now == len(B)-1:
            now = 0
        else:
            now += 1
    else:
        total_time += B[now]["time"]
        print("{} {}".format(B[now]["name"],total_time))
        del B[now]
        if now == len(B):
            now = 0
                        



Measured memory_bytes: 24384
#include<stdio.h>
int main(){
  int d1,d2,x,tmp;
  scanf("%d%d",&d1,&d2);
  if(d1<d2){
    tmp=d1;
    d1=d2;
    d2=tmp;
  }
  x=d1%d2;
  while(x!=0){
    d1=d2;
    d2=x;
    x=d1%d2;
  }
  printf("%d\n",d2);
  return 0;
}



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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

struct edge {
    int to, cost;
};

typedef vector<vector<edge> > AdjList;
AdjList graph;

typedef pair<int, int> P;

const int INF = 10000000;

vector<int> dist;
vector<int> prever;

void dijkstra(int n, int s){
    dist = vector<int>(n,INF);
    prever = vector<int>(n,-1);
    dist[s] = 0;

    priority_queue<P, vector<P>, greater<P> > que;
    que.push(P(0,s));

    while(!que.empty()){
        P p = que.top();
        que.pop();
        int v = p.second;
        if(dist[v] < p.first){
            continue;
        }
        for(int i=0;i<graph[v].size();i++){
            edge e = graph[v][i];
            if(dist[e.to] > dist[v] + e.cost){
                dist[e.to] = dist[v] + e.cost;
                prever[e.to] = v;
                que.push(P(dist[e.to],e.to));
            }
        }
    }
}

vector<int> get_path(int t){ //頂点tへの最短路
    vector<int> path;
    for(; t != -1;t=prever[t]){
        path.push_back(t);
    }

    reverse(path.begin(), path.end());
    return path;
}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,m;
  cin >> n >> m;
  VI from(m) , to(m);
  graph = AdjList(n);

  rep(i,m){
    cin >> from[i] >> to[i];
    from[i]--, to[i]--;
    graph[from[i]].push_back((edge){to[i],1});
  }
  ll minDist = INF;
  int f ,t;
  rep(i,m) {
    dijkstra(n,to[i]);
    if(dist[from[i]] != INF && minDist > dist[from[i]] ){
      minDist = dist[from[i]];
      f = from[i];
      t = to[i];
    }
  }
  if(minDist == INF) cout << -1 << endl;
  else{
    dijkstra(n,t);
    VI ans = get_path(f);
    cout << dist[f] + 1 << endl; // K
    for(int x: ans) cout << x+1 << endl;
    return 0;
  }

  return 0;
}


Measured memory_bytes: 384