akhauriyash/Code-Regression huggingface dataset:
import java.util.*
import kotlin.*

import java.io.InputStream
import java.lang.NumberFormatException
import java.lang.StringBuilder


fun main(args: Array<String>) {
    Program().solve()
}

class Program {
    fun solve() {
        val sc = FastScanner()
        val n = sc.nextLong()
        val m = sc.nextLong()
        val d = sc.nextLong()


        val ans = if (d == 0L) {
            (m - 1).toDouble() / n
        } else {
            ((n - d) * 2 * (m - 1)).toDouble() / (n * n).toDouble()
        }

        println(String.format("%.19f", ans))
    }
}


class FastScanner {
    companion object {
        val input: InputStream = System.`in`
        val buffer = ByteArray(1024) { 0 }
        fun isPrintableChar(c: Int): Boolean = c in 33..126
    }

    var ptr = 0
    var buflen = 0
    private fun hasNextByte(): Boolean {
        if (ptr < buflen) {
            return true
        } else {
            ptr = 0
            buflen = input.read(buffer)
            if (buflen <= 0) {
                return false
            }
        }
        return true
    }

    private fun readByte(): Int = if (hasNextByte()) buffer[ptr++].toInt() else -1

    private fun skipUnprintable() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr].toInt())) ptr++
    }

    fun hasNext(): Boolean {
        skipUnprintable()
        return hasNextByte()
    }

    fun next(): String {
        if (!hasNext()) throw NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b)
            b = readByte()
        }
        return sb.toString()
    }

    fun nextInt(): Int {
        if (!hasNext()) throw NoSuchElementException()
        var n = 0
        var b = readByte()
        // '-' = 45
        val minus = b == 45
        if (minus) {
            b = readByte()
        }

        // '0' = 48 '9' = 57
        if (b !in 48..57) {
            throw NumberFormatException()
        }

        while (true) {
            if (b in 48..57) {
                n *= 10
                n += b - 48
            } else if (b == -1 || !isPrintableChar(b)) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }

    fun nextLong(): Long {
        if (!hasNext()) throw NoSuchElementException()
        var n = 0L
        var b = readByte()
        // '-' = 45
        val minus = b == 45
        if (minus) {
            b = readByte()
        }

        // '0' = 48 '9' = 57
        if (b !in 48..57) {
            throw NumberFormatException()
        }

        while (true) {
            if (b in 48..57) {
                n *= 10
                n += b - 48
            } else if (b == -1 || !isPrintableChar(b)) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }

    fun nextDouble(): Double = next().toDouble()
}


Measured memory_bytes: 31268
#マンハッタン距離 |x| + |y| で 一番近いチェックポイント
#
#この問題では、xy格子上を縦、横に無駄なく歩いた場合の距離がマンハッタン距離。
#人がいる座標 (a, b) N 個、チェックポイントの座標 (c,d) M 個を 「リスト」 に格納。
#各人ごとに M 個 のチェックポイントをテストすることで、各人のマンハッタン距離が
#一番近いチェックポイントを求めることができる


INF = 1000000007

N, M = map(int, input().split())

ab = []

for i in range(N):
    ab.append([int(i) for i in input().split()])

cd = []

for i in range(M):
    cd.append([int(i) for i in input().split()])

for i in range(N):
    ans = 0
    dst = INF
    for j in range(M):
        tmp = abs(cd[j][0] - ab[i][0]) + abs(cd[j][1] - ab[i][1])

        if tmp < dst:
            # 0-indexed
            dst = tmp
            ans = j + 1

    print(ans)


Measured memory_bytes: 3064
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
from bisect import bisect_left
for i in range(n-2):
  for j in range(i+1, n-1):
    ab = l[i] + l[j]
    idx = bisect_left(l, ab)
    ans += max(idx-j-1, 0)
print(ans)

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

bool compare_by_second(pair<int,int> a,pair<int,int> b);
int main(void){
	int N;
	vector<pair<int,int>> jobs;
	cin>>N;
	for(int i=0;i<N;i++){
		int A,B;
		cin>>A>>B;
		pair<int,int> tmp = make_pair(A,B);
		jobs.push_back(tmp);
	}

	sort(jobs.begin(),jobs.end(),compare_by_second);
	
	int time = 0;
	for(int i=0;i<N;i++){
		pair<int,int> tmp = jobs.at(i);
		time += tmp.first;
		if(time > tmp.second){
			cout<<"No"<<endl;
			return 0;
		}
	}

	cout<<"Yes"<<endl;

	return 0;
}


bool compare_by_second(pair<int,int> a,pair<int,int> b){
	if(a.second != b.second){
		return a.second < b.second;
	}else{
		return a.first < b.first;
	}
}


Measured memory_bytes: 2420
import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
    public static void main(String[] args) throws Exception {
        
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s;
        try {
            while(true) {
                s = br.readLine();
                if(s.equals("0")) break;
                
                int sum = 0;
                for(int i = 0; i < s.length(); i++) {
                    sum += Character.getNumericValue(s.charAt(i));
                }
                System.out.println(sum);
            }
            
        } catch(IOException e) {
            e.printStackTrace();
        }
        
    }
}



Measured memory_bytes: 24340
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
#define LIMIT 1000000007 //10^9+7
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define all(v) (v).begin(), (v).end()

namespace /* debug */{
  #define DEBUG(...) do{cout<<#__VA_ARGS__<<" = ";debug(__VA_ARGS__);}while(0) //変数
  #define ldebug(...) do{cout<<"["<<setw(3)<<__LINE__<<"] ";debug(__VA_ARGS__);}while(0) //行数
  #define lDEBUG(...) do{cout<<"["<<setw(3)<<__LINE__<<"] "<<#__VA_ARGS__<<" = ";debug(__VA_ARGS__);}while(0) //変数, 行数
  template<class T>void show(T&x){cout<<x<<" ";} //出力
  template<class T>void showendl(T&x){cout<<x<<endl;} //出力改行
  template<class P,class Q>void show(pair<P,Q>&x){cout<<"("<<x.first<<", "<<x.second<<") ";} //pair出力
  template<class P,class Q>void showendl(pair<P,Q>&x){cout<<"("<<x.first<<", "<<x.second<<")"<<endl;} //pair出力改行
  template<class H>void debug(H&&h){showendl(h);} //引数1つ
  template<class H,class...Ts>void debug(H&&h,Ts&&...ts){show(h);debug(forward<Ts>(ts)...);} //可変引数
  template<class T>void debug(vector<T>&vt){int i=0;for(auto x:vt)++i!=vt.size()?show(x):showendl(x);} //vector出力
  template<class T>void debug(initializer_list<T>init){int i=0;for(auto x:init)++i!=init.size()?show(x):showendl(x);} //初期化子リスト出力
}

vi a, p;

ll f(ll n, ll x){
  if(n==0){
    return x<=0 ? 0 : 1;
  }
  if(x <= 1+a[n-1]){
    return f(n-1, x-1);
  }else{
    return p[n-1] + 1 + f(n-1, x-2-a[n-1]);
  }
}

int main(){
	ll N,X;cin>>N>>X;
  
  a.push_back(1);
  p.push_back(1);
  rep(i,N){
    a.push_back(a[i]*2 +3);
    p.push_back(p[i]*2 +1);
  }

  cout<<f(N,X)<<endl;
}

Measured memory_bytes: 3612
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
#define vv(a,b,c,d) vector<vector<a> >(b,vector<a>(c,d))
#define vvv(a,b,c,d,e) vector<vector<vector<a> > >(b,vv(a,c,d,e))
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    string s;
    int K;
    cin >> s >> K;
    int n = sz(s);
    vi t(n);
    rep(i, n - 1) {
        int a = s[i] - 'a';
        rep(j, 26) {
            rep(k, 26) {
                int b = (a + k) % 26;
                if (b == j&& k <= K) {
                    t[i] = j;
                    K -= k;
                    j = 99;
                    break;
                }
            }
        }
    }
    t.back() = (s.back() - 'a' + K) % 26;

    rep(i, n) {
        cout << (char)(t[i] + 'a');
    }
    cout << endl;
}

Measured memory_bytes: 976
n,x=map(int,input().split())

def f(n,x):
  if n==0:
    if x>0:return 1
    else:return 0
  if x<=(2**(n+2)-3-1)//2:
    return f(n-1,x-1)
  else:
    tmp=x-((2**(n+2)-3-1)//2+1)
    return 2**n-1+1+f(n-1,tmp)
  
print(f(n,x))

Measured memory_bytes: 3060
fn main() {
    let mut a: Vec<i32> =
        io::read_line().split_whitespace().map(|num| num.parse().unwrap()).collect();
    a.sort();
    println!("{}", a[0] + a[1]);
}

pub mod io {
    use std::io;

    pub fn read_line() -> String {
        let mut s = String::new();
        io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }

    pub fn readln<T: Read>() -> T {
        let mut s = String::new();
        io::stdin().read_line(&mut s).unwrap();
        T::read(s.trim())
    }

    pub trait Read {
        fn read(s: &str) -> Self;
    }

    impl Read for String {
        fn read(s: &str) -> Self {
            s.to_string()
        }
    }

    impl<T: Read> Read for Vec<T> {
        fn read(s: &str) -> Self {
            s.split_whitespace().map(|w| T::read(w)).collect()
        }
    }

    macro_rules !def_read {
        ($t : ty) => {
            impl Read for $t {
                fn read(s : &str)->$t { s.parse().unwrap() }
            }
        }
    }

    macro_rules !def_read_tuple {
        ($($t : ident), *) => {
            impl<$($t : Read + Default), *> Read for ($($t), *) {
                fn read(s : &str)->Self {
                    let mut iter = s.split_whitespace();
                    ($($t::read(iter.next().unwrap())), *)
                }
            }
        };
    }

    def_read!(i32);
    def_read!(i64);
    def_read!(isize);
    def_read!(usize);
    def_read!(f32);
    def_read!(f64);
    def_read_tuple!(T0, T1);
    def_read_tuple!(T0, T1, T2);
    def_read_tuple!(T0, T1, T2, T3);
    def_read_tuple!(T0, T1, T2, T3, T4);
}

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

int main () {
    string s; cin >> s;
    if (s == "RRR")
        cout << 3;
    else if ((s == "SRR") || (s == "RRS"))
        cout << 2;
    else if (s == "SSS")
        cout << 0;
    else 
        cout << 1;
}

Measured memory_bytes: 3588
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime> 
#include <memory.h>
#include <assert.h>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18 + 1;

const int MAX_N = 1e5+1;

struct UnionFind {
  vector<ll> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(ll x, ll y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(ll x, ll y) {
    return root(x) == root(y);
  }
  ll root(ll x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  ll size(ll x) {
    return -data[root(x)];
  }
};

int main(){
    ll N, M;
    cin >> N >> M;
    UnionFind uf(N);
    vector<pll> v;
    for(int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        v.push_back(pii(a, b));
    }

    reverse(v.begin(), v.end());

    vector<ll> ans;
    ll cnt = N*(N-1)/2; 
    for(auto e : v) {
        ans.push_back(cnt);
        int a = e.first, b = e.second;
        if(uf.findSet(a, b)) continue;
        ll sa = uf.size(a), sb = uf.size(b);
        cnt -= sa * sb;
        uf.unionSet(a, b);
    }

    reverse(ans.begin(), ans.end());
    for(int i = 0; i < ans.size(); i++) {
        cout << ans[i] << endl;
    }
    return 0;
}

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

int n, m, a[10], ce[7][70], co[7][70];
string id;

int main(){
    cin >> n >> id >> m;
    for(int i = 0; i < m; i++){
        cin >> a[i];
    }
    int ss = 0, ae = 0, ao = 0;
    for(int i = 1; i <= n; i++){
        if( id[n-i] >= '0' && id[n-i] <= '9' ){
            int m = id[n-i] - '0';
            m *= (2-i%2);
            ss += (1-i%2)*m/10 + m%10;
        }else{
            ao += i%2;
            ae += 1 - i%2;
        }
    }
    for(int i = 0; i < m; i++){
        co[0][a[i]] = 1;
    }
    for(int i = 1; i < ao; i++){
        for(int j = 0; j < 70; j++){
            if( co[i-1][j] ){
                for(int k = 0; k < m; k++){
                    co[i][j+a[k]] += co[i-1][j];
                }
            }
        }
    }
    for(int i = 0; i < m; i++){
        int aa = 2*a[i];
        aa = aa%10 + aa/10;
        ce[0][aa] = 1;
    }
    for(int i = 1; i < ae; i++){
        for(int j = 0; j < 70; j++){
            if( ce[i-1][j] ){
                for(int k = 0; k < m; k++){
                    int aa = 2*a[k];
                    aa = aa%10 + aa/10;
                    ce[i][j+aa] += ce[i-1][j];
                }
            }
        }
    }
    ae--; ao--;
    int ans = 0;
    for(int i = 0; i < 70; i++){
        if( !ce[ae][i] ) continue;
        for(int j = 0; j < 70; j++){
            if( !co[ao][j] || (i+j+ss)%10 ) continue;
            ans += ce[ae][i]*co[ao][j];
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1336
import java.lang.reflect.Field;
import java.util.*;

public class Main {

	static int limit = 21;
	static int mx[] = {0,1,0,-1};
	static int my[] = {1,0,-1,0};

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		while(true){
			int n = in.nextInt();
			if(n==0)break;
			int field[][] = new int[limit][limit];
			for (int i = 0; i < limit ; i++) {
				for (int j = 0; j < limit; j++) {
					field[i][j] = 0;
				}
			}
			for (int i = 0; i < n; i++) {
				int x = in.nextInt();
				int y = in.nextInt();
				field[x][y] = 1;
			}
			int nx = 10;
			int ny = 10;
			int cnt = 0;
			int m = in.nextInt();
			for (int i = 0; i < m; i++) {
				String direction = in.next();
				int move = in.nextInt();
				int d = 0;
				switch (direction) {
				case "N":
					d = 0;
					break;
				case "E":
					d = 1;
					break;
				case "S":
					d = 2;
					break;
				case "W":
					d = 3;
					break;
				default:
					break;
				}
				for (int j = 0; j < move; j++) {
					nx += mx[d];
					ny += my[d];
					if(field[nx][ny]==1){
						cnt++;
						field[nx][ny] = 0;
					}
				}
			}
			if(cnt==n){
				System.out.println("Yes");
			}else{
				System.out.println("No");
			}
		}
	}

}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n, a[200000], b[200000];

int main() {
	cin >> n;
	inc(i, n) { cin >> a[i]; b[i] = a[i]; }
	
	sort(b, b + n);
	int x = b[n / 2 - 1];
	int y = b[n / 2 - 0];
	
	inc(i, n) {
		cout << (a[i] <= x ? y : x) << "\n";
	}
	
	return 0;
}


Measured memory_bytes: 3712
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long x = sc.nextLong();
    long ans = 1;
    if(x > 6) {
      ans = Math.min(2 * (long)Math.ceil((double)x / (double)11), 2 * (long)Math.ceil((double)(x - 6) / (double)11) + 1);
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 22608
from itertools import permutations

N = int(input())
P = tuple([int(n) for n in input().split()])
Q = tuple([int(n) for n in input().split()])

a = 0
b = 0

for i, p in enumerate(permutations(range(1, N+1), N)):
    if p == P:
        a = i
    if p == Q:
        b = i
print(abs(a-b))


Measured memory_bytes: 9072
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <limits.h>
#include <map>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

int main() {
	int N, K, dummy;
	dummy = scanf("%d %d", &N, &K);

	vector<int> vi;
	map<int, int> mi;

	int tmp1;
	for (int i = 0; i < N; i++) {
		dummy = scanf("%d", &tmp1);
		vi.push_back(tmp1);
	}

	mi[0] = 0;

	for (int n = 1; n < N; n++) {
		int tmpMin = INT_MAX;
		for (int k = 1; k <= K; k++) {
			if (n < k) continue;
			int tmp = mi[n-k] + abs(vi[n] - vi[n-k]);
			tmpMin = min(tmpMin, tmp);
		}
		mi[n] = tmpMin;
	}
	
	printf("%d\n", mi[N-1]);
	
	return 0;
}


Measured memory_bytes: 5368
import java.util.*;

public class Main {
    public static void main(String[] args) {
        new Main().execute();
    }

    int N = 0;
    int A = 0;
    int B = 0;
    int C = 0;
    int[] l = null;

    class B {
        int d;
        int a;
        int b;
        int c;
        int p;

        B(int d, int a, int b, int c, int p) {
            this.d = d;
            this.a = a;
            this.b = b;
            this.c = c;
            this.p = p;
        }
    }

    public void execute() {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        A = sc.nextInt();
        B = sc.nextInt();
        C = sc.nextInt();

        l = new int[N];

        for (int i = 0; i < N; i++) {
            l[i] = sc.nextInt();
        }

        int r = Integer.MAX_VALUE;

        LinkedList<B> s = new LinkedList<>();
        s.push(new B(0, 0, 0, 0, 0));
        while (!s.isEmpty()) {
            B b = s.pop();

            if (b.d == N) {
                if (b.a != 0 && b.b != 0 && b.c != 0) {
                    r = Math.min(r, Math.abs(A - b.a) + Math.abs(B - b.b) + Math.abs(C - b.c) + b.p);
                }
                continue;
            }
            s.push(new B(b.d + 1, b.a, b.b, b.c, b.p));
            s.push(new B(b.d + 1, b.a + l[b.d], b.b, b.c, b.p + (b.a == 0 ? 0 : 10)));
            s.push(new B(b.d + 1, b.a, b.b + l[b.d], b.c, b.p + (b.b == 0 ? 0 : 10)));
            s.push(new B(b.d + 1, b.a, b.b, b.c + l[b.d], b.p + (b.c == 0 ? 0 : 10)));
        }
        System.out.println(r);
    }
}

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

using ll = long long;
using ull = unsigned long long;
using namespace std;
constexpr int inf = 1<<30;
constexpr int mo = 1e9+7;
constexpr ll infl = 1ll<<60;

int main(){
    cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    
    int h,w,k;
    cin>>h>>w>>k;
    vector<string> f(h);
    for(auto & a : f) cin>>a;
    int ret = 0;
    for(int hmask = 0; hmask<1<<h;++hmask){
        for(int wmask = 0;wmask < 1<<w;++wmask){
            int tmp = 0;
            for(int i=0;i<h;++i)for(int j=0;j<w;++j)if(!(hmask&1<<i) and !(wmask&1<<j) and f[i][j] == '#'){tmp++;
            }
            if(tmp == k)ret++;
        }
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 3636
n = int(input())
c1=0
c2=0
c3=0
c4=0
for I in range(1, n+1):
    s = str(input())
    if(s == "AC"):
        c1+= 1
    elif(s == "WA"):
        c2+=1
    elif(s == "TLE"):
        c3+=1
    elif(s == "RE"):
        c4 +=1
print(f"AC x {c1}")
print(f"WA x {c2}")
print(f"TLE x {c3}")
print(f"RE x {c4}")



Measured memory_bytes: 9152
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>

using namespace std;

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

  long long ans = 0;
  map<string, int> mp;
  for (int i = 0; i < n; i++) {
    string s; cin >> s;
    sort(s.begin(), s.end());
    mp[s]++;
    ans += mp[s]-1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 11136
program main
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: n,k,ans,si,i
    integer(int64), allocatable:: p(:), c(:)
        

    read*, n,k
    allocate(p(n), c(n))

    read*, p(:)
    read*, c(:)
    ans = -6e18
    do si=1,n
        block; integer(int64):: x, s(n), l, tot, now,t,e
            x = si
            l=0
            tot = 0
            do while(.true.)
                l=l+1
                x = p(x)
                s(l) = c(x)
                tot = tot + c(x)
                if (x == si) exit
            end do
            t=0
            do i=1,l
                t = t + s(i)
                if (i > k) exit
                now = t
                if (tot > 0)then
                    e = (k-i)/l
                    now = now + tot*e
                end if
                ans = max(ans, now)
            end do
        end block
    end do
    print'(i0)', ans
end program main

Measured memory_bytes: 3048
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	sc.Split(bufio.ScanWords)
	n, m := nextInt(), nextInt()

	x := make([]int, m)
	for i := 0; i < m; i++ {
		x[i] = nextInt()
	}
	sort.Ints(x)

	if n >= m {
		fmt.Println(0)
		return
	}

	slice := make([]int, m)
	ans := 0
	for i := 1; i < m; i++ {
		slice[i] = x[i] - x[i-1]
		ans += slice[i]
	}
	sort.Sort(sort.Reverse(sort.IntSlice(slice)))
	// fmt.Println(slice)
	for i := 0; i < n-1; i++ {
		ans -= slice[i]
	}

	fmt.Println(ans)
}


Measured memory_bytes: 2944
import itertools
import numpy as np

N, M, Q = map(int, input().split())
abcd = [list(map(int, input().split())) for i in range(Q)]


ans = 0
for A in itertools.combinations_with_replacement(range(1, M+1), N):
  score = []
  for i in range(Q):
    a = abcd[i][0]
    b = abcd[i][1]
    c = abcd[i][2]
    d = abcd[i][3]
    if A[b-1]-A[a-1] == c:
      score.append(d)
  ans = max(ans,sum(score))
print(ans)


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

const int maxn = 5005; 
using ll = long long; 

pair<ll, ll> p[maxn];
ll dp[maxn][maxn];

int main(int argc, char const *argv[])
{
//   freopen("in.txt", "r", stdin); 
   int n; 
   scanf("%d", &n); 
   for(int i = 1; i <= n; i++){
      scanf("%lld %lld", &p[i].first, &p[i].second);
   }
   sort(p + 1, p + n + 1, [&](pair<ll, ll> x, pair<ll, ll> y){
      return x.first + x.second < y.first + y.second;
   });
   memset(dp, 63, sizeof dp);
   dp[0][0] = 0; 
   for(int i = 1; i <= n; i++){
      for(int j = 1; j <= i; j++){
         if(dp[i - 1][j - 1] <= p[i].first){
            dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + p[i].second);
         }
         dp[i][j] = min(dp[i][j], dp[i - 1][j]);
      }
   }
   int ans = 5005;
   for(int i = 1; i <= n; i++){
      if(dp[n][i] < 1e14){
         ans = i;
      }
   }
   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 196096
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

a,b,c = iim()
ab = abs(a-b)
bc = abs(c-b)
ca = abs(a-c)
print(ab+bc+ca-max(ab,bc,ca))

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#define ll long long

using namespace std; 

int main(){
	int N, A, B;
	cin >> N >> A >> B;
	string s;
	cin >> s;
	int sum = 0;
	int sum_b = 0;
	for (int i = 0; i < N; ++i)
	 {
	 	if (s[i] == 'c')
	 	{
	 		cout << "No" << endl;
	 	}else if(s[i] == 'a' && sum < (A+B) ){
	 		cout << "Yes" << endl;
	 		sum++;
	 	}else if(s[i] == 'b' && sum < (A+B) && sum_b < B){
	 		cout << "Yes" << endl;
	 		sum++;
	 		sum_b++;
	 	}else{
	 		cout << "No" << endl;
	 	}
	 } 
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

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


		String[] splitS = s.split("");
//		for(int i = 0;i < splitS.length;i++) {
//			System.out.print(splitS[i]);
//		}
		int positionA = 0;
		for(int i = 0;i < splitS.length;i++) {
			if(splitS[i].equals("A")) {
				positionA = i;
				break;
			}
		}
		int positionZ = 0;
		for(int i = positionA;i < splitS.length;i++) {
			if(splitS[i].equals("Z")) {
				positionZ = i;
			}
		}
//		System.out.print(positionA);
//		System.out.print(positionZ);

//		for(int i = positionA;i <= positionZ;i++) {
			System.out.println(positionZ-positionA+1);
//	}
	}

}


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

using namespace std;

int main(void) {
    int n; cin >>n;
    vector<string> S(n);
    for (int i=0; i<n; i++) cin >> S[i];

    string ret="";
    for (char c='a'; c<='z'; c++) {
        int tmpmin=51;
        for (int i=0; i<n; i++) {
            int tmp=0;
            for (char s : S[i]) tmp += c == s;
            tmpmin = tmp < tmpmin ? tmp : tmpmin;
        }
        for (int i=0; i<tmpmin; i++) ret += c;
    }

    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 256
n,x,m=map(int,input().split())
ans=x
a=x
res=[x]
res2=0
r=0
for i in range(1,m+1):
    a=(a*a)%m
    if a==0:
        break
    if a in res:
        r=res.index(a)
        res2=i-r
        break
    else:
        ans+=a
        res.append(a)
b=[0]*m
for i in range(res2):
    b[i+1]=b[i]+res[r+i]
if res2==0:
    print(ans)
else:
    k=(n-r)//res2;l=(n-r)%res2
    ans+=b[res2]*(k-1)+b[l]
    print(ans)


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

int main()
{
    int n;
    cin >> n;
    vector<int> dp(3);
    for (int d = 0; d < n; d++)
    {
        vector<int> ndp(3, 0);
        vector<int> c(3);
        for (int &it : c)
            cin >> it;
        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                if (i != j)
                {
                    ndp[j] = max(ndp[j], dp[i] + c[j]);
                }
            }
        }
        dp = ndp;
    }
    cout << max({dp[0], dp[1], dp[2]});
}

Measured memory_bytes: 3632
#include <stdio.h>

long long dp[51][51][2501];

int main(void){
  int N,A;
  scanf("%d%d",&N,&A);

  int x[N];
  for(int i = 0;i < N;i++){
    scanf("%d",&x[i]);
  }

  dp[0][0][0] = 1;
  for(int i = 1;i <= N;i++){
    for(int j = 0;j <= N;j++){
      for(int k = 0;k <= 2500;k++){
        if(k >= x[i-1] && j != 0){
          dp[i][j][k] = dp[i-1][j][k]+dp[i-1][j-1][k-x[i-1]];
        }else{
          dp[i][j][k] = dp[i-1][j][k];
        }
      }
    }
  }

  long long ans = 0;
  for(int i = 1;i <= N;i++){
    ans += dp[N][i][A*i];
  }

  printf("%lld\n",ans);

  return 0;
}

Measured memory_bytes: 50048
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>
#include<utility>
#include<numeric>

#define pb push_back
#define mp make_pair
#define all(a)  (a).begin(),(a).end()
#define dwn(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)
#define V vector<int>
#define VV vector<V>
#define VVV vector<VV>

using namespace std;

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

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int INF = (int)1e9;
const ll inf = (ll)1e18;
const ll MOD{ (ll)1e9 + 7 };
const long double EPS = 1e-10;

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

	const int NMAX = 1000;
	const int MMAX = 2000;
	int a[MMAX], b[MMAX];
	ll c[MMAX];

	for (int i = 0; i < M; i++) {
		cin >> a[i] >> b[i] >> c[i];
		c[i] = -c[i];
	}

	ll dist[NMAX];

	for (int i = 0; i < N; i++) {
		dist[i] = inf;
	}

	dist[0] = 0;

	for (int loop = 0; loop < N - 1; loop++) {
		for (int i = 0; i < M; i++) {
			if (dist[a[i] - 1] == inf) continue;

			if (dist[b[i] - 1] > dist[a[i] - 1] + c[i]) {
				dist[b[i] - 1] = dist[a[i] - 1] + c[i];
			}
		}
	}

	ll ans = dist[N - 1];

	bool negative[NMAX];

	for (int i = 0; i < N; i++) {
		negative[i] = false;
	}

	for (int loop = 0; loop < N; loop++) {
		for (int i = 0; i < M; i++) {
			if (dist[a[i] - 1] == inf) continue;

			if (dist[b[i] - 1] > dist[a[i] - 1] + c[i]) {
				dist[b[i] - 1] = dist[a[i] - 1] + c[i];
				negative[b[i] - 1] = true;
			}

			if (negative[a[i] - 1] == true) {
				negative[b[i] - 1] = true;
			}
		}
	}

	if (negative[N - 1]) {
		cout << "inf" << endl;
	}
	else {
		cout << -ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		new Main();
	}

	public Main() {
		new B().doIt();
	}

	class B {
		class Data {
			int Team, accept, time;

			public Data(int Team, int accept, int time) {
				this.Team = Team;
				this.accept = accept;
				this.time = time;
			}
		}

		void doIt() {
			while (true) {
				int T = sc.nextInt();
				int P = sc.nextInt();
				int R = sc.nextInt();
				if(T+P+R == 0)break;
				int ans[][] = new int[501][501];
				int allTime[] = new int[501];
				int ac[] = new int[501];
				Data data[] = new Data[501];
				for (int i = 1; i < T + 1; i++) {
					data[i] = new Data(i, 0, 0);
				}
				for (int i = 0; i < R; i++) {
					int Ti = sc.nextInt();
					int Pr = sc.nextInt();
					int Time = sc.nextInt();
					String n = sc.next();
					if (n.equals("WRONG"))
						ans[Ti][Pr]++;
					else {
						allTime[Ti] = allTime[Ti] + (ans[Ti][Pr] * 1200) + Time;
						ac[Ti]++;
					}
				}
				for (int i = 1; i <= T; i++) {
					data[i] = new Data(i, ac[i], allTime[i]);
				}
				for (int i = 1; i < T; i++) {
					Data temp;
					for (int j = i + 1; j > 1; j--) {
						if (data[j].accept > data[j - 1].accept) {
							temp = data[j];
							data[j] = data[j - 1];
							data[j - 1] = temp;
						} else if (data[j].accept == data[j - 1].accept) {
							if (data[j].time < data[j - 1].time) {
								temp = data[j];
								data[j] = data[j - 1];
								data[j - 1] = temp;
							}
						}
					}
				}
				for (int i = 1; i <= T; i++) {
					System.out.println(data[i].Team + " " + data[i].accept+ " " + data[i].time);
				}
			}
		}
	}
}

Measured memory_bytes: 88472
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    class B_171_Mix_Juice
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数の入力
            var values = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();

            // 整数配列の入力
            var payment = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();

            int result = 0;

            Array.Sort(payment);

            for (int i = 0; i < values[1]; i++)
            {
                result = result + payment[i];
            }

            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 28648
import sys

inf = (1 << 31) - 1

def solve():
    n, q = map(int, sys.stdin.readline().split())

    bit = BinaryIndexedTree([0]*n)

    for qi in range(q):
        c, x, y = map(int, sys.stdin.readline().split())

        if c == 0:
            x -= 1
            bit.add(x, y)
        else:
            ans = bit.get_sum(y) - bit.get_sum(x - 1)
            print(ans)

class BinaryIndexedTree:
    def __init__(self, a):
        self.n = len(a)
        self.bit = [0]*(self.n + 1)

        for i in range(1, self.n + 1):
            self.bit[i] += a[i - 1]

            if i + (i & (-i)) <= self.n:
                self.bit[i + (i & (-i))] += self.bit[i]

    def add(self, i, x):
        i += 1

        while i <= self.n:
            self.bit[i] += x
            i += i & (-i)

    def get_sum(self, r):
        res = 0

        while r > 0:
            res += self.bit[r]
            r -= r & (-r)

        return res

class SegTree:
    def __init__(self, a):
        self.n = len(a)
        self.depth = 0

        while 2**self.depth < self.n:
            self.depth += 1

        self.data = [0]*(2**(self.depth + 1) - 1)

        self.data[2**(self.depth) - 1:2**(self.depth) - 1 + self.n] = a[:]

        for i in range(2**self.depth - 2, -1, -1):
            self.data[i] = self.data[2*i + 1] + self.data[2*i + 2]

    def add(self, i, x):
        i += 2**self.depth - 1
        self.data[i] += x

        while i > 0:
            i = (i - 1) // 2
            self.data[i] += x

    def get_sum(self, s, t, k, left, right):
        if t <= left or right <= s:
            return 0
        if s <= left and right <= t:
            return self.data[k]

        vl = self.get_sum(s, t, 2*k + 1, left, (left + right) // 2)
        vr = self.get_sum(s, t, 2*k + 2, (left + right) // 2, right)

        return vl + vr

if __name__ == '__main__':
    solve()

Measured memory_bytes: 10036
#include <bits/stdc++.h>
#define int long long

using namespace std;

const int ThaoNguyen = 5e6+5, mod = 998244353, inf = 1e15;

int gt[ThaoNguyen];

namespace THAONGUYEN
{
	string sum1(string a, string b)
	{
		string res="";
		int carry=0, x;
		while(a.length()<b.length())
		{
			a='0'+a;
		}
		while(b.length()<a.length())
		{
			b='0'+b;
		}
		for(int i=a.length()-1; i>=0; i--)
		{
			x=a[i]+b[i]-96;
			res=(char)(x%10+48+carry)+res;
			carry=x/10;
		}
		if(carry)
		{
			res='1'+res;
		}
		return res;
	}
	
	string mul1(string a, int b)
	{
		string res="";
		int carry=0, x;
		for(int i=a.length()-1; i>=0; i--)
		{
			x=(a[i]-48)*b+carry;
			res=(char)(x%10+48)+res;
			carry=x/10;
		}
		if(carry>0)
		{
			res=(char)(carry+48)+res;
		}
		return res;
	}
	
	string mul2(string a, string b)
	{
		string res="";
		for(int i=0; i<a.length(); i++)
		{
			res+='0';
			res=sum1(res, mul1(b, (int)(a[i]-48)));
			cout<<res<<endl;
		}
		return res;
	}
	
	void prep()
	{
		gt[1]=1;
		for(int i=2; i<ThaoNguyen-1; i++)
		{
			gt[i]=(gt[i-1]*i)%mod;
		}
	}
	
	int binpow(int n, int k, int mod)
	{
		int m = n%mod, i=1, ans=1;
		{
			while(i<=k)
			{
				int temp=i&k;
				if(temp>0)
				{
					ans=(ans*m)%mod;
				}
				i<<=1, m=(m*m)%mod;
			}
		}
		return ans;
	}
	
	int rev_mod(int n, int mod)
	{
		return binpow(n, mod-2, mod);
	}
	
	int C(int k, int n)
	{
		if(k==0||k==n)
		{
			return 1;
		}
		else
		{
			return ((((gt[n]%mod)*rev_mod(gt[k], mod))%mod)*rev_mod(gt[n-k], mod))%mod;
		}
	}
}

using namespace THAONGUYEN;

int n, m;

signed main()
{
	int ans=0;
	prep();
	cin>>n>>m;
	for(int i=0; i<=min(m, n); i++)
	{
		if((3*m-i)%2==0)
		ans+=(C(n-1, (3*m-i)/2+n-1)*C(i, n))%mod;
		ans%=mod;
	}
	int concac=0;
	for(int i=2*m+1; i<=3*m; i++)
	{
		concac+=C(n-2, n-2+(3*m-i))%mod;
		concac%=mod;
	}
	concac*=n;
	concac%=mod;
	cout<<(ans-concac+mod)%mod;
}

Measured memory_bytes: 39296
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) (x).begin(), (x).end()
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
  #define debug(x) cerr << #x " => " << x << endl
#else
  #define debug(x) 0
#endif
using lint = long long;
constexpr int    INF  = 1 << 30;
constexpr lint   INFL = 1LL << 62;
constexpr int    MOD  = (int)1e9 + 7;
constexpr double EPS  = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

using Weight = int;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(void) {}
  Edge(int src, int dst) : src(src), dst(dst) {}
  Edge(int src, int dst, Weight weight) : src(src), dst(dst), weight(weight) {}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void edges_to_graph(Graph &graph, const Edges &edges, const int vertices, const bool directed = true) {
  graph.resize(vertices);
  for (const auto &e : edges) graph[e.src].emplace_back(e);
  if (!directed) for (const auto &e : edges) graph[e.dst].emplace_back(Edge(e.dst, e.src, e.weight));
}

vector<double> calc_dp(const Graph &graph, const int dltv) {
  const int n = graph.size();
  vector<double> dp(n);
  rrep (i, n - 1) {
    double sum = 0, en = graph[i].size();
    if (i == dltv && en != 1) {
      double maxi = -1;
      allrep (e, graph[i]) {
        sum += dp[e.dst];
        maxi = max(maxi, dp[e.dst]);
      }
      sum -= maxi;
      --en;
    } else {
      allrep (v, graph[i]) sum += dp[v.dst];
    }
    dp[i] = sum / en + 1;
  }
  return dp;
}

int main(void) {
  int n, m;
  cin >> n >> m;
  Graph graph;
  Edges edges(m);
  rep (i, m) {
    int s, t;
    cin >> s >> t;
    edges[i] = {--s, --t};
  }
  edges_to_graph(graph, edges, n);
  vector<double> svp(n), nv(n);
  svp[0] = 1;
  rep (i, n - 1) {
    double p = svp[i] / graph[i].size();
    allrep (e, graph[i]) svp[e.dst] += p;
  }
  rrep (i, n - 1) {
    double sum = 0;
    allrep (e, graph[i]) sum += nv[e.dst];
    nv[i] = sum / graph[i].size() + 1;
  }
  double maxdec = 0;
  rep (i, n - 1) {
    const int en = graph[i].size();
    if (en == 1) continue;
    double maxi = -1;
    allrep (e, graph[i]) maxi = max(maxi, nv[e.dst]);
    double newnv = ((nv[i] - 1) * en - maxi) / (en - 1) + 1;
    maxdec = max(maxdec, (nv[i] - newnv) * svp[i]);
  }
  cout << nv[0] - maxdec << endl;
  return 0;
}

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

int main() {
  string a, b;
  cin >> a >> b;
  int l1 = a.size();
  int l2 = b.size();
  if(l1+1 != l2) {
    cout << "No" << endl;
  }
  bool p = true;
  for(int i=0; i<l1; i++) {
    if(a.at(i) != b.at(i)) {
      p = false;
      break;
    }
  }
  if(p) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3544
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

public class Program
{
    public static void Main(string[] args)
    {
        new Program().Solve(new ConsoleInput(Console.In, ' '));
    }

    public void Solve(ConsoleInput cin)
    {
        var a = cin.ReadIntArray(2);
        var n = a[0];
        var m = a[1];
        var x = "";
        var y = "";

        for (var i = 1; i < m+1; i++)
        {
            x += n.ToString();
        }

        for (var i = 1; i < n+1; i++)
        {
            y += m.ToString();
        }

        if (x.CompareTo(y) > 0)
        {
            WriteLine(y);
        }
        else
        {
            WriteLine(x);
        }

        ReadKey();
    }
}

public class ConsoleInput
{
    private readonly System.IO.TextReader _stream;
    private char _separator = ' ';
    private Queue<string> inputStream;
    public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
    {
        this._separator = separator;
        this._stream = stream;
        inputStream = new Queue<string>();
    }
    public string Read
    {
        get
        {
            if (inputStream.Count != 0) return inputStream.Dequeue();
            string[] tmp = _stream.ReadLine().Split(_separator);
            for (int i = 0; i < tmp.Length; ++i)
                inputStream.Enqueue(tmp[i]);
            return inputStream.Dequeue();
        }
    }
    public string ReadLine { get { return _stream.ReadLine(); } }
    public int ReadInt { get { return int.Parse(Read); } }
    public long ReadLong { get { return long.Parse(Read); } }
    public double ReadDouble { get { return double.Parse(Read); } }
    public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
    public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
    public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
}

Measured memory_bytes: 11484
n,t=input().split()
n=int(n)
t=int(t)
res=10000
for i in range(n):
  s=input().split()
  if int(s[1])<=t:
    res=min(res,int(s[0]))
if res==10000:
  print("TLE")
else:
  print(res)


Measured memory_bytes: 38384
//Try until you reach your goal
#include <bits/stdc++.h>
using namespace std;
# define ll long long
# define endl "\n"
# define str string
# define vll vector<ll>
# define pb push_back
# define mll map<ll,ll>
# define mp make_pair
# define ff first
# define ss second
# define pll pair<ll,ll>
# define f(x,y) for(int x=0;x<y;x++)
int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    str s;
    cin>>s;
    char c=s[s.length()-1];
    str s1="s";
    str s2="es";
    if(c=='s'){
        cout<<s<<s2;
    }
    else{
        cout<<s<<s1;
    }
    return 0;
}

Measured memory_bytes: 3652
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

	public static void main(String[] args) throws IOException{
		BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
		
		String str=in.readLine();
		
		boolean equals=str.charAt(2)==str.charAt(3)&&str.charAt(4)==str.charAt(5);
		if(equals) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		
		

	}

}


Measured memory_bytes: 20948
import java.util.*;

public class Main{
	
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	char[] o=sc.next().toCharArray(),e=sc.next().toCharArray();
    String s="";
    for(int i=0;i<o.length;i++){
      if(i==e.length){
        s+=o[i];
      }else{
        s+=o[i];
        s+=e[i];
      }
    }
    System.out.println(s);
  }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define mod 1000000007
 
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
 
int lcm(int a, int b) { return a * b / gcd(a, b); }

int main(){
    vector<int> w(10, 0);
    for (int i = 0; i < 6; i++){
        int a;
        cin >> a;
        w[a]++;
    }
    if(w[1] > 2 || w[2] > 2 || w[3] > 2 || w[4] > 2){
        cout << "NO" << endl;
    }else{
        cout << "YES" << endl;
    }
    return 0;
}

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

int main() 
{
    ll n,k;
    cin>>n>>k;
    ll a[n];
    for(ll i=0;i<n;i++)
    cin>>a[i];
    
    ll dp[n]={1000000009};
    dp[0]=0;
    
    for(ll i=1;i<n;i++)
    {
        dp[i]=1000000009;
        ll l=i-k;
        if(l<0)l=0;
    
        for(ll j=l;j<i;j++)
        {
            dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]));
        }
        
    }
    // for(ll i=0;i<n;i++)
    // cout<<dp[i]<<"  ";
    
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0168
{
    public class Program

    {
        public static void Main(string[] args)
        {

            const int MAX = 30;

            int[] dp = new int[MAX + 1];
            dp[0] = 1;
            dp[1] = 1;
            dp[2] = 2;

            for (int i = 3 ; i <= MAX ; i++)
            {
                dp[i] = dp[i - 1] + dp[i - 2] + dp[i - 3];
            }

            while (true)
            {
                int n = RInt(); if (n == 0) break;
                Console.WriteLine(dp[n] / 10 / 365 + 1);
            }
        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }

}



Measured memory_bytes: 15964
#include <stdio.h>
int main(void)
{

    int s,m,h;
    scanf("%d", &s);
    h=s/3600;
    m=(s%3600)/60;
    s=((s%3600)%60);
	printf("%d:%d:%d\n", h,m,s);
	
	return 0;
}



Measured memory_bytes: 2104
n=int(input())
l=list(map(int,input().split()))
l.sort()
ans=0
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if l[i]+l[j]>l[k] and l[i]!=l[j] and l[j]!=l[k]:
                ans+=1
print(ans)

Measured memory_bytes: 73544
#include <cstdio>
#include <algorithm>
#include <numeric>
#include <string>
#include <utility>
#include <vector>

int main() {
  size_t n;
  scanf("%zu", &n);

  std::vector<std::pair<std::string, int>> sp(n);
  for (auto& p: sp) {
    char buf[16];
    scanf("%s %d", buf, &p.second);
    p.first = buf;
  }

  std::vector<size_t> ind(n);
  std::iota(ind.begin(), ind.end(), 0);

  std::sort(ind.begin(), ind.end(), [&](size_t i, size_t j) {
    auto p = sp[i], q = sp[j];
    if (p.first != q.first) return p.first < q.first;
    return p.second > q.second;
  });

  for (auto ii: ind) printf("%zu\n", ii+1);
}


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

long long mod = 1e9+7;
vector< vector<int> > tree;
int k;

long long solve(int node,int from){
  long long ret = 1;
  int num = k-2;
  if(node == 0){
    ret = k;
    num = k-1;
  }
  for(int i = 0;i < tree[node].size();i++){
    if(tree[node][i] == from)continue;
    ret = (ret * solve(tree[node][i],node)) % mod;
    ret = (ret * num) % mod;
    num--;
  }
  return ret;
}

int main(){
  int n;
  cin >> n >> k;
  
  tree = vector< vector<int> >(n);

  for(int i = 0;i < n-1;i++){
    int u,v;
    cin >> u >> v;
    u--;v--;
    tree[u].push_back(v);
    tree[v].push_back(u);
  }
  cout << solve(0,-1) << endl;
}

Measured memory_bytes: 11520