akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define PART 1000
using namespace std;
pair<pair<int,int>,int> Q[500500];
inline bool Comp(pair<pair<int,int>,int> A,pair<pair<int,int>,int> B)
{
	if(A.first.first/PART==B.first.first/PART)
	{
		if(A.first.second<B.first.second)
			return true;
		return false;
	}
	if(A.first.first/PART<B.first.first/PART)
		return true;
	return false;
}
int X[500500],L,R,Sum;
int Ans[500500];
int Have[500500];
inline void read(int &x)
{
	while(true)
	{
	char c=getchar();
	if(c==' '||c=='\n')
		break;
//	cout<<"get"<<c<<endl;
	c-='0';
	x=x*10+c;
//	puts("Reading...");
	}
}
int main()
{
	int N=0,T=0;
	read(N);
	read(T);
//	cout<<N<<" "<<T<<endl;
	for(int i=0;i<N;i++)
		read(X[i]);
	for(int i=0;i<T;i++)
	{
		int l=0,r=0;
		read(l);
		read(r);
		l--;
		r--;
		Q[i]={{l,r},i};
	}
	sort(Q,Q+T,Comp);
//	for(int i=0;i<T;i++)
//		cout<<Q[i].second<<" ";
//	puts("");
	for(int i=Q[0].first.first;i<=Q[0].first.second;i++)
	{
		if(!Have[X[i]])
			Sum++;
		Have[X[i]]++;
	}
	L=Q[0].first.first;
	R=Q[0].first.second;//5e5*7e2=35e7
	Ans[Q[0].second]=Sum;
	for(int i=1;i<T;i++)
	{
		while(L<Q[i].first.first)
		{
			Have[X[L]]--;
			if(!Have[X[L]])
			{
				Sum--;
	//			puts("Minus!");
			}
			L++;
		}
		while(L>Q[i].first.first)
		{
			L--;
			if(!Have[X[L]])
			{
				Sum++;
				//puts("Add");
			}
			Have[X[L]]++;
		}
		while(R<Q[i].first.second)
		{
		//	cout<<R<<" "<<Q[i].first.second<<endl;
			R++;
			if(!Have[X[R]])
			{
				Sum++;
	//			puts("Add");
			}
			Have[X[R]]++;
		}
		while(R>Q[i].first.second)
		{
			Have[X[R]]--;
			if(!Have[X[R]])
				Sum--;
			R--;
		}
	//	cout<<Q[i].second<<" "<<Sum<<endl;
		Ans[Q[i].second]=Sum;
	}
	for(int i=0;i<T;i++)
	{
		printf("%d\n",Ans[i]);
	}
	return 0;
}


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

using namespace std;

long long _();
int main() { _(); return 0; }
#define main _
#define int long long 

int main()
{
    ios_base::sync_with_stdio(false);
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    int u[a], v[b], w[c];
    for(int i=0; i<a; i++)
        cin >> u[i];
    for(int i=0; i<b; i++)
        cin >> v[i];
    for(int i=0; i<c; i++)
        cin >> w[i];
    sort(u, u+a);
    sort(v, v+b);
    sort(w, w+c);
    int i = a-x, j = b-y, k = c-1;
    //cout << i << " " << j << " " << k+1 << endl;
    while(k >= 0 && (i < a && w[k] > u[i] || j < b && w[k] > v[j])) {
        if(j == b || u[i] < v[j])
            i++;
        else
            j++;
        k--;
    }
    //cout << i << " " << j << " " << k+1 << endl;
    int ans = 0;
    for(int h=i; h<a; h++)
        ans += u[h];
    for(int h=j; h<b; h++)
        ans += v[h];
    for(int h=k+1; h<c; h++)
        ans += w[h];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;
using P = pair<int, int>;
const int MOD = 1e9+7;
const double EPS = 1e-9;

vector<bool> seen, visited;

void dfs(const Graph &G, int v, vi &order, bool &able) {
  seen[v] = true;

  for (auto nv : G[v]) {
    if (seen[nv] && !visited[nv]) {
      able = false;
      return;
    }
    if (!seen[nv]) dfs(G, nv, order, able);

    if (!able) return;
  }

  order.push_back(v);
  visited[v] = true;
}

void solve() {
  int n; cin >> n;
  const int sz = n*(n-1)/2;

  Graph G(sz);
  vi start, finish;
  int prev, next;  // game number
  int tmp;
  vi sum(n, 0);

  rep(i,n) {
    cin >> tmp; --tmp;

    prev = sum[min(i,tmp)] + abs(i-tmp) - 1;
    start.push_back(prev);

    rep(j,n-2) {
      cin >> tmp; --tmp;

      next = sum[min(i,tmp)] + abs(i-tmp) - 1;
      G[prev].push_back(next);
      prev = next;
    }

    finish.push_back(next);
    sum[i+1] = sum[i] + (n-1)-i;
  }

  seen.assign(sz, false);
  visited.assign(sz, false);
  vi order;
  bool able = true;
  rep(i,n) {
    if (seen[start[i]]) continue;
    dfs(G, start[i], order, able);
    if (!able) {
      cout << -1 << endl;
      return;
    }
  }
  reverse(ALL(order));

  vi days(sz, 1);
  for (auto v : order) {
    for (auto nv : G[v]) {
      days[nv] = max(days[nv], days[v]+1);
    }
  }

  int ans = 0;
  rep(i,n) ans = max(ans, days[finish[i]]);
  cout << ans << endl;
}

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


Measured memory_bytes: 31856
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

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

const int N = 1e5 + 500;
const int M = 1e6 + 500;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;

ll gcd(ll A,ll B){
    if(!B) return A;
    return gcd(B,A % B);
}

ll x,y;

int main(){
    cin >> x >> y;
    ll lcm = x * y / gcd(x, y);
    lcm -= x;
    if(lcm % x == 0 && lcm % y != 0){
        cout << lcm << endl;
    }
    else{
        cout << -1 << endl;
    }
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.stream.Stream;

public class Main {

  public static void main(String[] args) throws Exception {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(br.readLine());
    // TODO あとでマイナス１する処理をつける
    int[] a = Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    br.close();

    int[][] dp = new int[n + 1][n + 1];
    for (int[] sub : dp) {
      Arrays.fill(sub, -1);
    }
    int[] colMax = new int[n + 1];
    Arrays.fill(colMax, -1);

    int base = 0;
    int dpMax = 0;
    dp[Math.min(a[0], a[1])][Math.max(a[0], a[1])] = 0;
    colMax[a[0]] = 0;
    colMax[a[1]] = 0;

    ArrayList<Query> queryList = new ArrayList<>();

    for (int loop = 1; loop < n; loop++) {
      int start = (loop * 3) - 1;
      if (a[start] == a[start + 1] && a[start] == a[start + 2]) {
        base++;
        continue;
      }
      queryList.clear();
      //揃える場合の遷移
      for (int temp = 0; temp < 3; temp++) {
        int x = a[start + (temp % 3)];
        int y = a[start + ((temp + 1) % 3)];
        int z = a[start + ((temp + 2) % 3)];
        //追加される3枚にペアがある場合
        if (x == y) {
          for (int i = 1; i <= n; i++) {
            if (dp[Math.min(i, x)][Math.max(i, x)] >= 0) {
              queryList.add(new Query(Math.min(i, z), Math.max(i, z),
                  dp[Math.min(i, x)][Math.max(i, x)] + 1));
            }
          }
        } else {
          //xを採用
          if (dp[x][x] >= 0) {
            queryList.add(new Query(Math.min(y, z), Math.max(y, z), dp[x][x] + 1));
          }
        }
      }

      for (int temp = 0; temp < 3; temp++) {
        int x = a[start + (temp % 3)];
        int y = a[start + ((temp + 1) % 3)];
        //int z = a[start + ((temp + 2) % 3)];
        //揃えない場合
        //xのみ採用
        for (int i = 1; i <= n; i++) {
          if(colMax[i] >= 0){
            queryList.add(new Query(Math.min(i, x), Math.max(i, x), colMax[i]));
          }
        }
        //xyを採用
        queryList.add(new Query(Math.min(x,y), Math.max(x,y), dpMax));
      }

      for (Query q : queryList) {
        dpMax = Math.max(dpMax, q.value);
        colMax[q.a] = Math.max(colMax[q.a], q.value);
        colMax[q.b] = Math.max(colMax[q.b], q.value);
        dp[q.a][q.b] = Math.max(dp[q.a][q.b], q.value);
      }
    }
    System.out.println(Math.max(dp[a[a.length - 1]][a[a.length - 1]] + 1, dpMax) + base);
  }
}

class Query {

  int a, b, value;

  Query(int a, int b, int value) {
    this.a = a;
    this.b = b;
    this.value = value;
  }
}

Measured memory_bytes: 76168
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define INF (1 << 30)
#define INFLL (1LL << 60)

int main() {
	ll n, a[100001] = {}, sorted[100001] = {};
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> a[i];
		sorted[i] = a[i];
	}
	sort(sorted, sorted + n);
	map<ll, ll> map;
	for(int i = 0;i < n;i++){
		map[sorted[i]] = i + 1;
	}

	ll ans = 0;
	for(int i = 0;i < n;i += 2){
		ll now = a[i];
		if(map[a[i]] % 2 == 0){
			ans++;
		}
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8064
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;in(__VA_ARGS__)
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
void vout(vl V) {
	for (ll i = 0; i < (ll)V.size(); i++) cout << V[i] << " ";
	cout << endl;
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//bitSearch, bitList, nod, gcdlcm, isPrime, primeFactorize, Npow, divisor, modinv, dfs, bfs, eratos//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007; ll INF = 1LL << 62; ll ans = 0; ll z = 0, o = 1;
vl flag, color; vll path; vl A; vl dp; vl Ans;
int main() {
	cin >> N >> M;
	vl H(N);
	for (i = 0; i < N; i++) cin >> H[i];
	path.resize(N);
	for (i = 0; i < M; i++) {
		ll a, b;
		cin >> a >> b;
		a--; b--;
		path[a].push_back(b);
		path[b].push_back(a);
	}
	for (i = 0; i < N; i++) {
		ll valid = 1;
		for (j = 0; j < path[i].size(); j++) {
			if (H[i] <= H[path[i][j]]) {
				valid = 0;
			}
		}
		if (valid) ans++;
	}
	cout << ans;
}

Measured memory_bytes: 9856
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	int n,m;
	List<List<Integer>> graph;
	static int[] memo;//graph.get(i)の有向パスの最大を記録
	static boolean f[];//memo[i]に記録されているならばtrue;

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

	private void solve() {
		n = nextInt();
		m = nextInt();
		graph = new ArrayList<List<Integer>>();
		for(int i=0;i<=n;i++)graph.add(new ArrayList<Integer>());
		for(int i=0;i<m;i++)graph.get(nextInt()).add(nextInt());

		f = new boolean [n+1];
		memo = new int [n+1];
		int res = 0;
		for(int i=1;i<=n;i++)if(!f[i])res = Math.max(res,memo[i]=SearchVerticesPass(i));

		System.out.println(res);
	}

	private int SearchVerticesPass(int vi) {
		if(f[vi])return memo[vi];
		List<Integer>V = graph.get(vi);
		int cntmax=0;
		for(int i=0;i<V.size();i++)cntmax=Math.max(SearchVerticesPass(V.get(i))+1, cntmax);
		f[vi]=true;
		return memo[vi] = cntmax;
	}

	private int nextInt() {
		return Integer.parseInt(sc.next());
	}
}

Measured memory_bytes: 73344
# ABC 097 C

from collections import defaultdict

S = input()
K = int(input())

alphabet = defaultdict(list)
for i, s in enumerate(S):
    alphabet[s].append(i)

alpha_list = sorted(alphabet.keys())
cand = []
i = 0
while len(cand) < K:
    for j in alphabet[alpha_list[i]]:
        if len(S)-j+1 >= K:
            for l in range(1, K+1):
                cand.append(S[j:j+l])
        else:
            for l in range(1, len(S)-j+1):
                cand.append(S[j:j+l])
    cand = list(set(cand))
    if len(cand) >= K:
        break
    i += 1
cand = sorted(cand)
print(cand[K-1])

Measured memory_bytes: 4928
while True:
    num = list(map(int,input().split()))
    if(num[0] == 0 and num[1] == 0): break
    else:
        flag = False
        for i in range(num[0]):
            str = ""
            if(i == 0 or i == num[0]-1): flag=True
            else: flag=False
            for j in range(num[1]):
                if(j == 0 or j == num[1]-1 or flag):
                    str = str + "#"
                else:
                    str = str + "."
            print(str)
        print()
                    


Measured memory_bytes: 5616
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll n,ans=1;
  bool zeros=false,o=false;
  cin>>n;
  vector<ll> a(n);
  for(ll i=0;i<n;i++){
    scanf("%lld",&a[i]);
    if(a[i]==0) zeros=true;
  }if(!zeros){
    for(ll i=0;i<n;i++){
      if(ans>1000000000000000000/a[i]){
        o=true;
      }else{
        ans*=a[i];
      }
    }
  }
  if(zeros) cout<<0<<endl;
  else if(o) cout<<-1<<endl;
  else cout<<ans<<endl;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

LL n,dp[20][20];
string ans="";

LL count(LL len)
{
	memset(dp,0,sizeof(dp));
	repn(i,9) dp[0][i]=1;
	rep(i,len-1)
	{
		rep(j,10)
		{
			if(dp[i][j]==0) continue;
			if(j+1<=9) dp[i+1][j+1]+=dp[i][j];
			dp[i+1][j]+=dp[i][j];
			if(j-1>=0) dp[i+1][j-1]+=dp[i][j];
		}
	}
	LL ret=0;
	rep(i,10) ret+=dp[len-1][i];
	return ret;
}

LL conditionalCount(LL fir,LL len)
{
	memset(dp,0,sizeof(dp));
	dp[0][fir]=1;
	rep(i,len-1)
	{
		rep(j,10)
		{
			if(dp[i][j]==0) continue;
			if(j+1<=9) dp[i+1][j+1]+=dp[i][j];
			dp[i+1][j]+=dp[i][j];
			if(j-1>=0) dp[i+1][j-1]+=dp[i][j];
		}
	}
	LL ret=0;
	rep(i,10) ret+=dp[len-1][i];
	return ret;
}

int main()
{
	cin>>n;
	LL len,tmp;
	repn(i,15)
	{
		tmp=count(i);
		if(tmp>=n)
		{
			len=i;
			break;
		}
		n-=tmp;
	}
	for(int i=len;i>0;i--)
	{
		for(int j=(i==len ? 1:ans[ans.size()-1]-'0'-1);j<(i==len ? 10:ans[ans.size()-1]-'0'+2);j++)
		{
			tmp=conditionalCount(j,i);
			if(tmp>=n)
			{
				ans.pb(j+'0');
				break;
			}
			n-=tmp;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3600
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		BigDecimal A = new BigDecimal(sc.next());
		BigDecimal B = new BigDecimal(sc.next());
		A = A.multiply(B);
		System.out.println(A.setScale(0, RoundingMode.DOWN));
	}

}


Measured memory_bytes: 35960
n,m,x = map(int,input().split())
a = list(map(int,input().split()))
cost0 = 0
cost1 = 0
for i in range(x+1,n):
    if(i in a):
        cost0 += 1
for i in range(0,x):
    if(i in a):
        cost1 += 1
print(min(cost0,cost1))

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
using namespace std;

int main() {
    int H;
    int W;
    int K;
    cin >> H >> W >> K;

    vector <string> valRow(H);

    for (int i = 0; i < H; ++i) {
        cin >> valRow[i];
    }

    int rowCho = 1<<H;
    int colCho = 1<<W;

    // 2^6 * 2^6 * W*H = 4096 * 6 * 6
    int ans = 0;

    for (int rc = 0; rc < rowCho; ++rc) {
        for (int cc = 0; cc < colCho; ++cc) {
            vector <string> newRow(valRow.begin(), valRow.end());
            vector <bool> rowSet(H);
            vector <bool> colSet(W);

            const char RED = '.';

            for (int i = 0; i < H; ++i) {
                if (rc & (1<<i)) {
                    rowSet[i] = true;
                }
            }

            for (int i = 0; i < W; ++i) {
                if (cc & (1<<i)) {
                    colSet[i] = true;
                }
            }

            for (int i = 0; i < H; ++i) {
                for (int j = 0; j < W; ++j) {
                    if (rowSet[i] || colSet[j]) {
                        newRow[i][j] = RED;
                    }
                }
            }

            int cnt = 0;
            for (int i = 0; i < H; ++i) {
                for (int j = 0; j < W; ++j) {
                    if (newRow[i][j] != RED) {
                        ++cnt;
                    }
                }
            }

            if (cnt == K) {
                ++ans;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <string.h>


int main(void)
{
	int a, b, c, cnt=0, flag=0, aa;
	
	scanf("%d %d %d", &a, &b, &c);
	aa = a;
	do{
		
		if(aa % b == c){ printf("YES\n"); flag = 1; break;}
		cnt++;
		aa = aa + a;
	}while(cnt<999999);
	
	if(flag==0) printf("NO\n");



	//getchar();
	//getchar();
	return 0;
}


Measured memory_bytes: 128
S = input()
T = input()

scores = {0}

for i in range(len(T)):
  for j in range(i, len(S) - len(T) + i + 1):
    if T[i] == S[j]:
      score = 1
      for k in range(1, len(T) - i):
        if T[i + k] == S[j + k]:
          score += 1
      scores.add(score)
      
print(len(T) - max(scores))

Measured memory_bytes: 73744
let scan_int () = Scanf.scanf " %d" (fun x -> x)
let scan_array len read_func = Array.init len (fun _ -> read_func())
let print_int n = Printf.printf "%d\n" n

let rec binary_search left right array value =
  if right - left <= 1 then right
  else
    let mid = (left + right) / 2 in
    if array.(mid) < value then binary_search mid right array value
    else binary_search left mid array value
  

let () =
  let n = scan_int() in
  let l = scan_array n scan_int in
  let _ = Array.fast_sort compare l in
  let ans = ref 0 in
  let _ =
    for i = 0 to n-2 do
      for j = i+1 to n-1 do
        let sum = l.(i) + l.(j) in
        let k = binary_search j n l sum in
        ans := !ans + (k-j-1)
      done
    done in
  print_int !ans


Measured memory_bytes: 896
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		ULL N; cin >> N;
		UL ans = 0;
		while (N >= 10) {
			if (N % 10 == 9) { ans += 9; N /= 10; }
			else { ans += 9; N /= 10; N -= 1; }
		}
		ans += N;
		cout << ans << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define MAXN 100000
#define rint register int
inline int read(){int r;int s=0,c;for(;!isdigit(c=getchar());s=c);for(r=c^48;isdigit(c=getchar());(r*=10)+=c^48);return s^45?r:-r;}
vector<int> e[MAXN+5]; int s[MAXN+5], c[MAXN+5], n, r, f, m, Ans; string S = "B", _;
void DFS(int p, int fa){s[p] = S[p]=='W', c[p] = (S[p]!='B')^!!fa; for(auto v:e[p]) if(v^fa) DFS(v,p), s[p] += s[v], c[p] ^= !!s[v];}
void Dia(int p, int fa, int d){d>m||(d==m&&!c[p])?m=d,f=p:0; for(auto v:e[p]) if(s[v]&&v^fa) Dia(v,p,d+(c[v]<<1));}
void Cal(int p, int fa){Ans += c[p]; for(auto v:e[p]) if(s[v]&&v^fa) Cal(v,p), Ans += 2;}
int main()
{
	n = read(); for(rint i = 2, a, b; i <= n; a = read(), b = read(), e[a].push_back(b), e[b].push_back(a), i++); cin >> _, S = S+_;
	if(~(r=S.find('W'))) DFS(r,0), Cal(r,0), Dia(f=r,0,m=c[r]<<1), Dia(r=f,0,m=c[f]<<1), Ans -= m-((c[r]&&c[f])<<1); return !printf("%d\n",Ans);
}

Measured memory_bytes: 12928
// https://atcoder.jp/contests/abcXXX/tasks/abcXXX_x

#include <iostream>
#include <vector>
#include <tuple>

using namespace std;
using ll = long long;

struct C {
    ll K_{};
    ll X_{};
    explicit C(ll K, ll X) : K_(K), X_(X){}
    vector<ll> resolve() {
        vector<ll> ret{};
        ll start = max(-1000000LL, X_-K_+1);
        ll end = min(1000000LL, X_+K_-1);
        for(ll i= start; i <= end; ++i) {
            ret.emplace_back(i);
        }
        return ret;
    }
};

int main() {
    ll K, X;
    cin >> K >> X ;
    C c{K, X};
    for(auto a : c.resolve()) {
        cout << a << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int w,h,n;
    cin>>h>>w;
    for(int i=0;i<h;i++){
        char s[102];
        cin>>s;
        n=0;
        for(int j=0;j<w;j++){
        if(j>0)cout<<" ";
        if(s[j]=='c'){
            n=1;
            cout<<"0";
        }else if(n>0){
            cout<<n;
            n++;
        }else{
            cout<<"-1";
        }

        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 3076
N = int(input())
A = list(map(int,input().split()))
ans = 1
A.sort()
for i in A:
  ans *= i
  if i == 0:
    print(0)
    break
  if ans > 10**18:
    print("-1")
    break
if ans <= 10**18 and ans !=0:
  print(ans)

Measured memory_bytes: 21780
a,b,c,d=input().split()
a=int(a)
b=int(b)
c=int(c)
d=int(d)
if c<a<d:
  if b>d:
    print(d-a)
  else:
    print(b-a)
if a<=c:
  if b<c:
    print(0)
  elif c<=b<=d:
    print(b-c)
  else:
    print(d-c)
if a>=d:
  print(0)


Measured memory_bytes: 9188
from collections import deque
from enum import Enum, auto

class Color(Enum):
    WHITE = auto()
    GRAY = auto()
    BLACK = auto()

n = int(input())
d = [0 for i in range(n)]
f = [0 for i in range(n)]

colors = [] # 頂点の訪問状態
A = [[0 for j in range(n)] for i in range(n)] # 隣接行列
queue = deque([])

# 隣接行列の初期化
for i in range(n):
    arr = list(map(int, input().split(' ')))
    u, k, v = arr[0], arr[1], arr[2:]
    for j in range(k):
        A[u-1][v[j]-1] = 1

def bfs():
    global colors, queue, d
    colors = [Color.WHITE for i in range(n)]
    d = [-1 for i in range(n)] # INF

    colors[0] = Color.GRAY
    d[0] = 0
    queue.append(0)

    while len(queue) > 0:
        u = queue.popleft()
        for v in range(n):
            if A[u][v] == 1 and colors[v] == Color.WHITE:
                colors[v] = Color.GRAY
                d[v] = d[u] + 1
                queue.append(v)
        colors[u] = Color.BLACK

bfs()

for i in range(n):
    print(i+1, d[i])



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

long long K, X;
int main(){
	cin >> K >> X;
	long long s = X-K + 1;
	long long e = X+K - 1;
	for(long long i = s; i<=e; i++){
		cout << i;
		if(i == e){
			cout << endl;
		}else{
			cout << " ";
		}
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

class UnionFind
{
public:
	UnionFind(ll size) : parent(size), rank(size), diff_weight(size) {
		for (ll i = 0; i < size; i++) {
			parent[i] = i;
			rank[i] = 0;
			diff_weight[i] = 0;
		}
	};

	ll root(ll x) {
		if (parent[x] == x) {
			return x;
		}
		else {
			ll p = root(parent[x]);
			diff_weight[x] += diff_weight[parent[x]];
			return parent[x] = p;
		}
	}

	bool same(ll x, ll y) {
		return root(x) == root(y);
	}

	bool unite(ll x, ll y, ll w) {
		w += weight(x) - weight(y);

		x = root(x);
		y = root(y);
		if (x == y) return false;

		if (rank[x] < rank[y]) {
			parent[x] = y;
			diff_weight[x] = -w;
		}
		else {
			parent[y] = x;
			diff_weight[y] = w;
			if (rank[x] == rank[y]) rank[x]++;
		}

		return true;
	}

	ll weight(ll x) {
		root(x);
		return diff_weight[x];
	}

	ll diff(ll x, ll y) {
		return diff_weight[y] - diff_weight[x];
	}

private:
	//parent[i]==j  : iの親がj
	vector<ll> parent;
	vector<ll> rank;
	vector<ll> diff_weight;

};

ll N;
vector<ll> vec;

void solve() {
	cin >> N;
	vec.resize(N);
	rep(i, N) cin >> vec[i];

	UnionFind UF(N);

	rep(i, N) {
		if (i == N-2) {
			UF.unite(N-2, 0, (vec[N-1] - vec[N-2]) * 2);
			continue;
		}
		if (i == N - 1) {
			UF.unite(N - 1, 1, (vec[0] - vec[N - 1]) * 2);
			continue;
		}
		UF.unite(i, i + 2, (vec[i + 1] - vec[i]) * 2);
	}

	vector<ll> ans(N);
	rep(i, N) {
		ans[i] = UF.weight(i);
	}

	ll diff = (vec[0] * 2 - ans[0] - ans[1]) / 2;

	rep(i, N) cout << ans[i] + diff << " ";

}

int main() {
	solve();
	cout << endl;
	return 0;
}


Measured memory_bytes: 5248
// A

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
int N,c[100000];
vector<int> G[100001];
int ans[100001] = {0};
int pathed_dfs[100001] = {0};
ll sum(0);

void dfs(int now){
  pathed_dfs[now]++;
  for (int i(0);i<G[now].size();i++){
    int next = G[now][i];
    if (pathed_dfs[next] == 0){
      sum += min(ans[now],ans[next]);
      dfs(next);
    }
  }
}

int main(){
  cin>>N;
  for (int i(0);i<N-1;i++){
    int a,b;
    cin>>a>>b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  for (int i(0);i<N;i++) cin>>c[i];
  sort(c,c+N,greater<int>());
  queue<int> q;
  int pathed[100001] = {0};
  q.push(1);
  int cnt(0);
  while(!q.empty()){
    int now = q.front();q.pop();
    ans[now] = c[cnt];
    cnt++;
    pathed[now] = 1;
    for (int i(0);i<G[now].size();i++){
      int next = G[now][i];
      if (pathed[next] == 0){
        q.push(next);
      }
    }
  }
  dfs(1);
  cout << sum << endl;
  for (int i(1);i<=N;i++) cout << ans[i] << " ";
  return 0;
}


Measured memory_bytes: 3968
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
using namespace std;

unsigned long long int attack(unsigned long long int n){
    n /= 2llu;
    if(n<=1) return 1;
    else{
        return 2llu*attack(n) + 1llu;
    }
}
int main(){
    unsigned long long int n = 0;
    cin >> n;
    if(n==0)cout << 0 << endl;
    else if(n==1) cout << 1 << endl;
    else printf("%llu\n", 2llu*attack(n) + 1llu);


    return 0;
}

Measured memory_bytes: 256
S = list(input())

for i in range(len(S)):
    S[i] = int(S[i])

f = S[0]
ans = 0

for i in range(1,len(S)):
    if S[i]+S[i-1] != 1:
        ans += 1
        S[i] = int(not S[i])

print(ans)

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;

struct UnionFind {
    vector<int> par, rank;

    UnionFind(int N) : par(N), rank(N) {
        rep(i, N) par[i] = i, rank[i] = 0;
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        if (rank[rx] < rank[ry]) {
            par[rx] = ry;
        }
        else {
            par[ry] = rx;
            if (rank[rx] == rank[ry]) rank[rx]++;
        }
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

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

    vector<int> group[M], cnt(N, 0);
    rep(i, N) {
        int K;
        cin >> K;
        rep(j, K) {
            int l;
            cin >> l;
            group[l - 1].push_back(i);
        }
    }

    UnionFind tree(N);

    rep(i, M) {
        repd(j, 1, group[i].size()) {
            tree.unite(group[i][j - 1], group[i][j]);
        }
    }

    int ans = 0;
    rep(i, N) {
        cnt[tree.root(i)]++;
    }

    rep(i, N) {
        chmax(ans, cnt[i]);
    }

    if (ans == N) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 4736
#include <stdio.h>
int main(void)
{
    int A,B,C,K;
    scanf("%d%d%d%d",&A,&B,&C,&K);
    if(A+B>=K){
        if(A>=K)
            printf("%d\n",K);
        else
            printf("%d\n",A);
    }
    else
        printf("%d\n",A-(K-(A+B)));
    return 0;
}


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

int main() {
   int n;
   cin>>n;
   string s;
   cin>>s;
   int t=s.length();
   
   if(t<=n)
   cout<<s;
   else
   {
       for(int x=0; x<n; x++)
       cout<<s[x];
       cout<<"...";
   }
}

Measured memory_bytes: 3588
class Dic:
    def __init__(self):
        self.end = False
        self.a = self.c = self.g = self.t = 0
    def insert(self, s):
        node = self
        index = 0
        while index < len(s):
            c = s[index]
            child = 0
            if c == 'A':
                if not node.a:
                    node.a = Dic()
                child = node.a
            elif c == 'C':
                if not node.c:
                    node.c = Dic()
                child = node.c
            elif c == 'G':
                if not node.g:
                    node.g = Dic()
                child = node.g
            elif c == 'T':
                if not node.t:
                    node.t = Dic()
                child = node.t
            else:
                return
            node = child
            index += 1
        node.end = True
    def find(self, s):
        node = self
        index = 0
        while index < len(s):
            c = s[index]
            child = 0
            if c == 'A':
                child = node.a
            elif c == 'C':
                child = node.c
            elif c == 'G':
                child = node.g
            elif c == 'T':
                child = node.t
            if child == 0:
                return False
            node = child
            index += 1
        return node.end

dic = Dic()

n = int(input())
for _ in range(n):
    cmd = list(input().split())
    if cmd[0] == 'insert':
        dic.insert(cmd[1])
    elif cmd[0] == 'find':
        print('yes' if dic.find(cmd[1]) else 'no')



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

typedef long long ll;
typedef long double ld;

#define imx INT_MAX
#define imn INT_MIN
#define llmx LLONG_MAX
#define llmn LLONG_MIN

#define fi first
#define se second
#define pb push_back



/////////////////////GCD//////////////////////
ll gcd(ll a, ll b)
{
	if(b==0) return a;
	return gcd(b, a%b);
}


////////////////////SIEVE OF ERATOSTHENES//////////////////////
vector<int> sieveoferatosthenes(int n)
{
	vector<bool> prime(n+1, true);
	for(int i = 2; i <= sqrt(n); i++)
	{
		if(prime[i])
		{
			for(int j = i*i; j<=n; j+=i)
			{
				prime[j]=false;
			}
		}
	}
	vector<int> all_primes;
	for(int i = 2; i <=n; i++)
	{
		if(prime[i]) all_primes.pb(i);
	}
	return all_primes;
}



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, k;
	cin>>n>>k;
	ll mod = 1000000007;
	ll ans = 0;
	vector<ll> a(n+2, 0);
	a[1]=n+1;
	ll start=1;
	ll diff=-2;
	for(int i = 2; i <= n+1; i++)
	{
		a[i]=((i%mod*n%mod)%mod+(start+diff+mod)%mod)%mod;
		// cout<<a[i]<<"  ";
		start=(start%mod+diff%mod+mod)%mod;
		diff=(diff-2+mod)%mod;
	}
	for(int i = k; i <=n+1; i++)
	{
		ans=(ans%mod+a[i]%mod)%mod;
	}
	cout<<ans%mod<<endl;
}

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

#define rep(i, a, b) for(int i = (a); i <= (b); ++i)
#define per(i, b, a) for(int i = (b); i >= (a); --i)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define boost ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define M (ll)(1e9+7)
#define inf (ll)(2e9+9)
#define infl (ll)(2e18+9)
#define debug1(a) cout<<#a<<" = " <<a<<endl; 
#define debug2(a,b) cout<<#a<<" = " <<a<<" , "<<#b<<" = "<<b<<endl; 
#define debug3(a,b,c) cout<<#a<<" = " <<a<<" , "<<#b<<" = "<<b<<" , "<<#c<<" = "<<c<<endl; 
#define debug4(a,b,c,d) cout<<#a<<" = " <<a<<" , "<<#b<<" = "<<b<<" , "<<#c<<" = "<<c<<" , "<<#d<<" = " <<d<<endl; 
  
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<char> vc; 
typedef vector<ll> vll; 
typedef vector< pair<int,int> > vpii;

/* -------------------------------------------------------------------------*/
/* -------------------------------------------------------------------------*/

const int maxn=100000+5; 
int n,m; 
vi adj[maxn]; 
int dp[maxn]; 
int vis[maxn]; 

void dfs(int u){
  vis[u]=1; 
  for(int v:adj[u]){
    if(vis[v]) dp[u]=max(dp[u],dp[v]+1); 
    else { 
      dfs(v); 
      dp[u]=max(dp[u],dp[v]+1); 
    }
  }
}


void solve(){
  cin>>n>>m; 
  rep(i,1,m){
    int u,v; cin>>u>>v; 
    adj[u].push_back(v); 
  }
  rep(i,1,n){
    if(!vis[i]){
      dfs(i); 
    }
  }
  int ans=0; 
  rep(i,1,n) ans=max(ans,dp[i]); 
  cout<<ans; 
}

int main() {
  clock_t beg=clock(); 
  boost;
  int t=1; 
  // cin>>t; 
  while(t--){
    solve(); 
  }
  clock_t end=clock(); 
  fprintf(stderr, "%lf\n", (double)(end-beg)/CLOCKS_PER_SEC);
}


Measured memory_bytes: 8576
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath> // sqrt
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#define ps(arr) \
    debug("size %ld: ", arr.size()); \
    for(auto e: arr) cout << e << " "; \
    cout << endl;
#else
#define debug(fmt, ...)
#define ps(arr)
#endif


int main(void) {
    int num; int sum;
    cin >> num >> sum;

    vector<int> ans(3, -1);
    for(int i = 0; i <= num; i++) {
        for(int j = 0; j <= num-i; j++) {
            int k = num - i - j;
            if(k < 0) continue;
            int money = i * 10000 + j * 5000 + k * 1000;
            if(money == sum) {
                ans[0] = i; ans[1] = j; ans[2] = k;
                goto finish;
            }
        }
    }
finish:
    for(auto e: ans) cout << e << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 3600
# Studying https://img.atcoder.jp/abc164/editorial.pdf

# Inputs

N,M,S = gets.split.map(&:to_i)
E = Array.new(N){ [] }
M.times.map{
	u,v,a,b = gets.split.map(&:to_i)
	E[u-1] << [v-1,a,b]
	E[v-1] << [u-1,a,b]
}
X = N.times.map{ gets.split.map(&:to_i) }

# Tools

class PQ
	def initialize
		@h = [] # min-heap
	end

	def enq(v)
		@h.push(v)
		up_heap
	end

	def deq
		max, last = @h[0], @h.pop
		unless @h.empty?
			@h[0] = last
			dn_heap
		end
		return max
	end

private
	def up_heap
		i, up = @h.size-1, @h[-1]
		while 0 <= (iP = (i-1)/2)
			break unless up < @h[iP]
			@h[i], i = @h[iP], iP
		end
		@h[i] = up
	end

	def dn_heap
		i, dn, size = 0, @h[0], @h.size
		while (iC = 2*i+1) < size
			iC += 1 if iC+1 < size and @h[iC+1] < @h[iC]
			break unless @h[iC] < dn
			@h[i], i = @h[iC], iC
		end
		@h[i] = dn
	end
end

R = lambda{|t,s,u|
	next t<<18 | [s,4095].min<<6 | u
}
Я = lambda{|r|
	next r>>18, r>>6&4095, r&63
}

# Main

n,T,２ = 0, [nil]*N, [-1]*N
Q = PQ.new; Q.enq R[0,S,0]
while r = Q.deq
	t,s,u = Я[r]

	next if s <= ２[u] # 銭なしの再訪に用なし
	２[u] = s

	unless T[u] # first arrived.
		n, T[u] = n+1, t
		break if n == N # completed.
	end

	E[u].each{|v,a,b|
		Q.enq R[t+b,s-a,v] if ２[v] < s-a
	}

	c,d = X[u]
	Q.enq R[t+d,s+c,u]
end

# Output

T.shift
p(*T)

__END__

こういう入力に弱い。

9 8 0
1 2 50 1
2 3 50 1
3 4 50 1
4 5 50 1
5 6 50 1
6 7 50 1
7 8 50 1
8 9 50 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1


Measured memory_bytes: 14528
#include <stdio.h>
const int MAX_V = 1000000; 
int prime[1000000+1];
int prime_sum[1000000+1];
int main() {
	int i, k, v;
	for(i = 2; i <= MAX_V; i++) {
		prime[i] = 1;
	}
	for(i = 2; i*i <= MAX_V; i++) {
		if(prime[i]) {
			for(k = 2 * i; k <= MAX_V; k += i) {
				prime[k] = 0;
			}
		}
	}
	for(i = 0; i <= MAX_V; i++){
		prime_sum[i] = prime_sum[i-1] + prime[i-1];
	}
	while(scanf("%d", &v) != EOF) {
		printf("%d\n",prime_sum[v+1]);
	}
return 0;
}

Measured memory_bytes: 8404
#include <iostream>

using namespace std;

int main(void) {
	int n, ans = 0;
	cin >> n;
	while (n > 0) {
		ans += n % 10;
		n /= 10;
	}
	if (ans == 1)
		printf("10\n");
	else
		printf("%d\n", ans);
	return 0;
}

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

#define SZ(x) ((int(x.size())))

typedef long long ll;
typedef long double ld;

using namespace std;

const int maxn = 2*1000+10;
int ans = maxn, k, d[maxn], tmp, n, u, v, a[maxn], b[maxn];
vector <int> vec[maxn];

void dfs (int x, int p)
{
    if (d[x] > k / 2)
        tmp++;
    for (int i = 0; i < SZ(vec[x]); i++)
    {
        if (vec[x][i] != p)
        {
            d[vec[x][i]] = d[x] + 1;
            dfs (vec[x][i], x);
        }
    }
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> k;
    if (k & 1)
    {
        for (int i = 0; i < n - 1; i++)
        {
            cin >> a[i] >> b[i];
            a[i]--;
            b[i]--;
            vec[a[i]].push_back (b[i]);
            vec[b[i]].push_back (a[i]);
        }
        for (int i = 0; i < n - 1; i++)
        {
            tmp = 0;
            d[a[i]] = 0;
            dfs (a[i], b[i]);
            d[b[i]] = 0;
            dfs (b[i], a[i]);
            ans = min (ans, tmp);
        }
    }
    else
    {
        for (int i = 0; i < n - 1; i++)
        {
            cin >> u >> v;
            u--;
            v--;
            vec[u].push_back (v);
            vec[v].push_back (u);
        }
        for (int i = 0; i < n; i++)
        {
            tmp = 0;
            d[i] = 0;
            dfs (i, -1);
            ans = min (ans, tmp);
        }
    }
    cout << ans;
	return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int T = sc.nextInt();
    int mincost = 1001;

    for (int i = 0; i < n; i++) {
      int c = sc.nextInt();
      int t = sc.nextInt();
      if ((mincost > c) && (T >= t)) {
        mincost = c;
      }
    }

    if (mincost > 1000) {
      System.out.println("TLE");
    } else {
      System.out.println(mincost);
    }

  }
}

Measured memory_bytes: 36076
#include<bits/stdc++.h> 
using namespace std;
char arr[100000];
int main()
{
	int n;
	int ind=0;
	int a,b,c;
	cin>>n>>a>>b>>c;
	string cur;
	cin>>cur;
	for(int i=0;i<n;i++)
	{
		if(cur=="AB")
		{
			if(a>b)
			{
				arr[ind++]='B';
				if(i<n-1)cin>>cur;
				a--;
				b++;
				continue;
			}
			if(a<b)
			{
				arr[ind++]='A';
				if(i<n-1)cin>>cur;
				a++;
				b--;
				continue;
			}
			if(a==b&&a==0)
			{
				cout<<"No"<<endl;
				return 0;
			}
			if(a==b&&a!=0)
			{
				if(i<n-1)
					cin>>cur;
				else
				{
					arr[ind++]='A';
					break;
				}
				if(cur=="AB")
				{
					arr[ind++]='A';
					arr[ind++]='B';
				  	i++;
				  	if(i<n-1)
				  		cin>>cur;
					continue;
				}
				if(cur=="AC")
				{
					arr[ind++]='A';
					a++;
					b--;
				  continue;
				}
				if(cur=="BC")
				{
					arr[ind++]='B';
					b++;
					a--;
					continue;
				}
				
			}
		}
		if(cur=="BC")
		{
			if(b>c)
			{
				arr[ind++]='C';
				if(i<n-1)cin>>cur;
				c++;
				b--;
				continue;
			}
			if(c>b)
			{
				arr[ind++]='B';
				if(i<n-1)cin>>cur;
				b++;
				c--;
				continue;
			}
			if(c==b&&c==0)
			{
				cout<<"No"<<endl;
				return 0;
			}
			if(c==b&&c!=0)
			{
				if(i<n-1)
					cin>>cur;
				else
				{
					arr[ind++]='C';
					break;
				}
				if(cur=="BC")
				{
					arr[ind++]='C';
					arr[ind++]='B';
				  	i++;
				  	if(i<n-1)
					  	cin>>cur;
				  	continue;
				}
				if(cur=="AC")
				{
					arr[ind++]='C';
					c++;
					b--;
				  	continue;
				}
				if(cur=="AB")
				{
					arr[ind++]='B';
					b++;
					c--;
					continue;
				}
			}
		}
		if(cur=="AC")
		{
			if(a>c)
			{
				arr[ind++]='C';
				if(i<n-1)cin>>cur;
				c++;
				a--;
				continue;
			}
			if(c>a)
			{
				arr[ind++]='A';
				if(i<n-1)
					cin>>cur;
				a++;
				c--;
				continue;
			}
			if(c==a&&c==0)
			{
				cout<<"No"<<endl;
				return 0;
			}
			if(c==a&&c!=0)
			{
				if(i<n-1)
					cin>>cur;
				else
				{
					arr[ind++]='A';
					break;
				}
				if(cur=="AC")
				{
					arr[ind++]='C';
					arr[ind++]='A';
				  	i++;
				  	if(i<n-1)cin>>cur;
				  	continue;
				}
				if(cur=="BC")
				{
					arr[ind++]='C';
					c++;
					a--;
				  continue;
				}
				if(cur=="AB")
				{
					arr[ind++]='A';
					a++;
					c--;
					continue;
				}
			}
		}
	}
	cout<<"Yes"<<endl;
	for(int i=0;i<ind;i++)
		cout<<arr[i]<<endl;
	return 0;
}

Measured memory_bytes: 3668
using System;

namespace abc078A
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            int A = int.Parse(str[0], System.Globalization.NumberStyles.HexNumber);
            int B = int.Parse(str[1], System.Globalization.NumberStyles.HexNumber);
            if (A > B)
                Console.WriteLine(">");
            else if (A == B)
                Console.WriteLine("=");
            else
                Console.WriteLine("<");
        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
int a[10005];
int main(){
	int n, x, max, min;
	cin >> n;
	for(int i = 1; i <= n; i++){
		scanf("%d", &x);
		if(i == 1){
			max = x;
			min = x;
		}
		else{
			if(max < x){
				max = x;
			}
			if(min > x){
				min = x;
			}
		}
	}
	cout << max - min;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
void fastIO(){
  ios_base::sync_with_stdio(0); cin.tie(0);
}


int main(){
  fastIO();
  ll x,y;
  cin>>x>>y;
  int ans = 0;
  while(x<=y){
  	ans++;
  	x*=2;
  }
  cout<<ans<<endl;
}









Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    int a,b;
    cin>>s>>t;
    cin>>a>>b;
    string u;
    cin>>u;
    if(u==s)
        a--;
    else
        b--;
    cout << a<<" " << b<<endl;
    return 0;
}


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

using namespace std;

int main(){
  int n;
  cin >> n;
  
  vector<int> a1(n);
  vector<int> a2(n);
  for(int i=0; i<n; i++) cin >> a1[i];
  for(int i=0; i<n; i++) cin >> a2[i];
  
  vector<int> s1(n+1, 0);
  vector<int> s2(n+1, 0);
  
  for(int i=0; i<n; i++){
    s1[i+1] = s1[i] + a1[i];
    s2[i+1] = s2[i] + a2[i];
  }
  
  
  int max_a = 0;
  for(int i=0; i<n; i++){
    max_a = max(max_a, s2[n]-s2[i]+s1[i+1]);
  }
  
  cout << max_a << endl;
  
  return 0;
}

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

main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  int Ans=0;
  for(int i=1; i<N-1; i++){
    
    int cnt=0;
    
    for(char c='a'; c<='z'; c++){
      
      bool left =false, right =false;      
      
      for(int j=0; j<i; j++){
        if(S[j] ==c)
          left =true;
      }
      
      for(int k=i; k<N; k++){
        if(S[k] ==c)
          right =true;
      }  
      
      if(left && right)
        cnt++;
    }  
    
    if(Ans < cnt)
      Ans =cnt;
  }    
  cout << Ans;
  return 0;
}  

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

using namespace std;

int main(){
  int n;
  bool flag=true;
  cin >> n;
  vector<int> a;
  for(int i=0;i<n;i++){
    int tmp=0;
    cin >> tmp;
    if(tmp%2==0){
      a.push_back(tmp);
    }
  }

  for(int i=0;i<a.size();i++){
    if( !(a.at(i)%3==0 || a.at(i)%5==0) ){
      flag=false;
      break;
    }
  }

  if(flag){
    cout << "APPROVED" << endl;
  }
  else{
    cout << "DENIED" << endl;
  }
  return 0;
}


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

int main(){
  int n,i,count=0;
  cin>>n;
  char x[n];
  for (i=0;i<n;i++)cin>>x[i];
  for (i=1;i<n;i++){
    if ((x[i]=='O'&&x[i-1]=='X')||(x[i-1]=='O'&&x[i]=='X')){count++;i++;}
  }
  cout<<count<<endl;
}



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

using namespace std;

#define MAX_N 1001
#define INF 1e16
#define ll long long
struct edge {
    int from; //出発点
    int to;   //到達点
    ll cost; //移動コスト
};

vector<bool> v;
vector<vector<int>> g;
bool dfs(int nowv,int tv){
    // nowvからtvにいけるかどうか調べる
    if(nowv==tv)return true;
    for(int i=0;i<g[nowv].size();i++){
        int next = g[nowv][i];
        if(v[next])continue;
        v[next] = 1;
        if(dfs(next,tv))return true;
        v[next] = 0;
    }
    return false;
}
int main()
{
    int N; //頂点の数
    int M; //辺の数
    int S; //始点
    int G; //終点
    
    vector<edge> edges; //移動の情報を保存する

    cin >> N;
    cin >> M;
    vector<ll> d(N,INF);
    g.resize(N);
    S = 0;
    G = N-1;
    v.resize(N);

    d[S] = 0; //始点を0にする

    for (int i = 0; i < M; i++) {
        struct edge add;
        cin >> add.from;
        cin >> add.to;
        cin >> add.cost;
        add.from--;
        add.to--;
        add.cost *= -1;
        edges.push_back(add);
        g[add.from].push_back(add.to);
    }

    vector<int> inf;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {

            struct edge e = edges[j];

            if (d[e.to] > d[e.from] + e.cost) {  //移動した後のコストが大きいと、頂点のコストを更新
                d[e.to] = d[e.from] + e.cost;
                if (i == N-1) {         //頂点の数と同じ回数ループすると、負の閉路があるのでループをぬける
                    inf.push_back(e.from);
                    break;
                } 
            }
        }
    }
    bool ok = 0;
    for(auto x:inf){
        // xからゴールにいけるかどうかを調べる
        v[x] = 1;
        if(dfs(x,G))ok = 1;
        v[x] = 0;
    }
    if(ok)cout << "inf" << endl;
    else cout << -d[G] << endl;
}


Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())




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

	string s,t;
	cin>>s;
	t=s;
	reverse(all(t));
	if (s == t)cout << "Yes"<<endl;
	else cout << "No"<<endl;



	return 0;
}

Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let sw: Vec<i32> = read_vec();
    println!("{}", if sw[0] > sw[1] {"safe"} else {"unsafe"})
}

Measured memory_bytes: 2136