akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

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

  vector<int> P(M);
  vector<int> C(N), E(N);
  for(auto& i: P) cin >> i;
  for(int i = 0; i < N; ++i) cin >> C[i] >> E[i];

  vector<int> dp(20000 + 1, INT_MAX >> 1);
  dp[0] = 0;
  for(int j = 0; j < N; ++j) for(int k = 20000; C[j] <= k; --k) dp[k] = min(dp[k], dp[k - C[j]] + E[j]);

  sort(begin(P), end(P), greater<int>());
  int answer = 0;
  int sum = 0;
  for(int i = 1; i <= 20000; ++i) {
    if(i <= M) sum += P[i-1];
    answer = max(answer, sum - dp[i]);
  }
  cout << answer << endl;
}

Measured memory_bytes: 1332
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int bitcount(int a) {
    int c = 0;
    while (a) c++, a&=a-1;
    return c;
}

int dp[1<<10][400], ans[16][400];

int main() {
    dp[0][0] = 1;
    rep (b, 1<<10) {
        const int c = bitcount(b);
        rep (i, 10) if (!(b&(1<<i))) {
            rep (s, 400) if (dp[b][s]) {
                dp[b|(1<<i)][s+(c+1)*i] += dp[b][s];
            }
        }
        rep (s, 400) if (dp[b][s]) ans[c][s] += dp[b][s];
    }
    int n, s;
    while (scanf("%d%d", &n, &s) != EOF) {
        printf("%d\n", n < 16 && s < 400 ? ans[n][s] : 0);
    }
    return 0;
}

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

using namespace std;

// ensure has mid
int f(vector<int>& a) {
    int n = a.size();
    vector<int> coeff(n);
    for (int i = 0; i < n; i++) {
        coeff[i] = (i&(n-1-i)) ? 0 : 1;
    }
    int sum = 0;
    for (int i = 0; i < n; i++) {
        sum ^= ((a[i]&1) * coeff[i]);
    }
    return sum;
}

void solve() {
    int n; cin >> n;
    bool notwo = true;
    vector<int> a(n);
    string s; cin >> s;
    for (int i = 0; i < n; i++) {
        a[i] = s[i]-'0';
        if (a[i]==2) notwo = false;
    }

    if (notwo) {
        vector<int> b(n-1);
        for (int i = 1; i < n; i++) {
            b[i-1] = abs(a[i]-a[i-1]);
            b[i-1] /= 2;
        }
        cout << f(b)*2;
    } else {
        cout << f(a);
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 13084
#include <bits/stdc++.h>
using namespace std;
const int MAX = 100;

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

    int N;
    cin >> N;
    double ret = 0;
    for (int i = 0; i < N; i++) {
        double a;
        cin >> a;
        ret += (1 / a);
    }
    ret = (1 / ret);
    cout << fixed << ret << endl;


    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };
const int c_div = 1000000007; //10^9 + 7

bool but[20];


int main() {

	int N, L;
	scanf("%d%d", &N, &L);
	char S[200][200];
	for (int i = 0; i < N; i++) {
		scanf("%s", S[i]);
	}
	for (int i = 0; i < N; i++)
		for (int j = i + 1; j < N; j++)
			if (strcmp(S[i], S[j]) > 0) {
				char temp[200];
				for (int k = 0; k < L; k++) {
					temp[k] = S[i][k];
					S[i][k] = S[j][k];
					S[j][k] = temp[k];
				}
			}

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < L; j++) {
			printf("%c", S[i][j]);
		}
	}




}


Measured memory_bytes: 128
#include <iostream>
#include <string.h>
using namespace std;
 
int main() {
  char ch[4];
  cin >> ch[0] >> ch[1] >> ch[2] >> ch[3];

  if(ch[0] == ch[1] && ch[1] == ch[2]){
    cout << "Yes" << endl;
  } else if(ch[1] == ch[2] && ch[2] == ch[3]){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

using namespace std;

typedef long long ll;


ll dfs(string s) {
    stringstream ss(s);
    ll x = 0;
    ss >> x;
    if (s.length() == 1) return x;
    for (int i = 1; i < s.length(); i++) {
        string left = s.substr(0, i);
        string right = s.substr(i);

        stringstream ss2(left);
        ll leftNum = 0;
        ss2 >> leftNum;

        int rightNum = dfs(right);
        x += leftNum * pow(2, right.length()-1) + rightNum; 
    }
    return x;
}


void solve() {
    string s; cin >> s;
    cout << dfs(s) << endl;    
}


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

Measured memory_bytes: 384
#include <iostream>

using namespace std;

int n,g;
int an[13];
int bn[13];
int min1;

bool qu[13];
void jisuan(int now,int yijiejue,int earn)
{
    int i,j;
    //cout<<earn<<"ada"<<endl;
    if (earn >=g)
    {
        min1=min(min1,yijiejue);
        //cout<<earn<<"1"<<endl;;
        return ;
    }
    //cout<<"17"<<endl;
    if (now==n)
    {
        //cout<<now<<endl;
        for (i=n-1;i>=0; i--)
        {
            //cout<<i<<endl;
            if(qu[i])
                continue;
            j=an[i];
            while(j--)
            {
                if (earn >=g)
                {
                    min1=min(min1,yijiejue);
                    //cout<<earn<<endl;;
                    return ;
                }
                yijiejue+=1;
                earn+=100*(i+1);
            }
            earn+=bn[i];
        }
        return;
    }
    qu[now]=true;
    //cout<<"dsada"<<endl;
    jisuan(now+1,yijiejue+an[now],earn+an[now]*100*(now+1)+bn[now]);
    qu[now]=false;
    //cout<<1<<endl;
    jisuan(now+1,yijiejue,earn);
}


int main()
{

    int i;
    min1=0x3f3f3f3f;
    cin >>n>>g;
    for (i=0; i<n; i++)
    {
        cin>>an[i]>>bn[i];
        qu[i]=false;
    }
    jisuan(0,0,0);

    cout << min1 << endl;
    return 0;
}


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;

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

    int N;
    cin >> N;

    vll adjrow(N, 0);
    vvll adjmat(N, adjrow);

    for(int i=0;i<N;i++) {
        for(int j=0;j<N;j++) cin >> adjmat[i][j];
    }

    int M = (1 << N);

    vll dp(M, 0);
    for(int i=1;i<M;i++) {
        vi cur;
        for(int j=0;j<N;j++) {
            if (((1<<j) & i) != 0) cur.push_back(j);
        }

        int S = cur.size();
        if (S == 1) continue;

        ll allscore = 0;
        for(int j=0;j<S;j++) {
            for (int k=0;k<j;k++) {
                allscore += adjmat[cur[j]][cur[k]];
            }
        }

        dp[i] = max(dp[i], allscore);

        int T = (1 << S);
        for(int j=1; j < T-1; j++) {
            int subi = 0;
            for(int b=0;b<S;b++) {
                if (((1<<b) & j) != 0) {
                    subi += (1<<cur[b]);
                }
            }
            ll subscore = dp[subi] + dp[i ^ subi];
            dp[i] = max(dp[i], subscore);
        }
    }

    cout << dp[M-1] << endl;

    return 0;
}

Measured memory_bytes: 896
#include<stdio.h>
#define MAX 10000

int Lis(int *,int,int);

int main() {

  int num[MAX];
  int n,m,i,key,count=0;

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

  scanf("%d",&m);
  for(i=0;i<m;i++) {
    scanf("%d",&key);
    if( (Lis(num,n,key)) == 1 ) count++;
  }

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

  return 0;

}

int Lis(int *num,int n,int key) {

  int i=0;
  num[n] = key;

  while( num[i] != key) i++;

  if(i>=n) return 0;
  else return 1;

}


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

/* {{{ */
#define PI(N) ((M_PI * (N)) / 180) //角度をラジアンに変換する
#define CL(N) (cout << (N) << endl)
#define DCT(N) (cout << "debug " << (N) << endl)
#define REP(i, N) for (int i = 0; i < (N); i++)
/* }}} */

int main()
{
    string s;

    cin >> s;

    REP(i, s.size()){
        if (s[i] == ','){
            s[i] = ' ';
        }
    }

    CL(s);

    return (0);
}


Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n=parseInt(readline())
    s=chomp(readline())
    k=parseInt(readline())
    for i in s
        if i==s[k]
            print(i)
        else
            print("*")
        end
    end
end
main()

Measured memory_bytes: 110304
n, k = gets.split.map(&:to_i)
ps = gets.split.map(&:to_i)

sum = 0
k.times do |i|
  sum += ps[i]
end

mx = sum

k.upto(n - 1) do |i|
  sum += ps[i] - ps[i - k]
  mx = [sum, mx].max
end

p((mx + k).to_f / 2)


Measured memory_bytes: 18692
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll n,k;
  cin>>n>>k;
  set<ll> se;
  map<ll,ll> ma;
  for(ll i=0;i<n;i++){
    ll a,b;
    cin>>a>>b;
    ma[a]+=b;
    se.insert(a);
  }
  ll c=0;
  for(ll s:se){
    c+=ma[s];
    if(c>=k){
      cout<<s;
      return 0;
    }
  }
}


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

typedef long long ll;

const int N = 3e5 + 10;
int n, a[N], sa[N];
char s[N];
vector<pair<int, int> > e;
ll ans;

int main() {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]);
        for (int j = 0; j < 20; ++j)
            if ((1 << j) & a[i])
                e.emplace_back(j, i);
    }
    int eplace = 0;
    int esz = e.size();
    for (int i = 1; i <= n; ++i) {
        static int b[30];
        memset(b, 0, sizeof b);
        while (eplace < esz && e[eplace].second < i)
            eplace++;
        int j = eplace;
        while (j < esz && !b[e[j].first]) {
            b[e[j].first] = 1;
            j++;
        }
        int endp = n + 1;
        if (j < esz) endp = e[j].second;
        // cout << i << " " << endp << endl;
        ans += endp - i;
    }
    cout << ans << endl;
}


Measured memory_bytes: 18792
#pragma GCC optimize("O3")
#include <iostream>
#include <climits>
#include <stdlib.h>

using namespace std;

int main(void) {
    unsigned int n,cities[100001],heroes[100000];
    unsigned long ans = 0;

    cin >> n;
    for (int i = 0; i <= n; i++) {
        cin >> cities[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> heroes[i];
    }

    for (int i = 0; i < n; i++) {
        if (cities[i] > heroes[i]) {
            ans += heroes[i];
            heroes[i] = 0;
        } else {
            ans += cities[i];
            heroes[i] -= cities[i];
            if (cities[i+1] > heroes[i]) {
                ans += heroes[i];
                cities[i+1] -= heroes[i];
            } else {
                ans += cities[i+1];
                cities[i+1] = 0;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

const int INF = 19191919;

using Point = pair<int,int>;

bool solve(int n, int m){
    vector<Point> b(n),w(m);
    rep(i,n) cin >>b[i].x >>b[i].y;
    rep(i,m) cin >>w[i].x >>w[i].y;

    rep(i,n)rep(j,m){
        int A = w[j].y - b[i].y;
        int B = b[i].x - w[j].x;
        int C = b[i].y*w[j].x - b[i].x*w[j].y;

        bool ok = true;
        vector<pair<Point,int>> on_line;

        int bp = 0, bm = 0;
        rep(k,n){
            int v = A*b[k].x + B*b[k].y + C;

            if(v>0) ++bp;
            else if(v<0) ++bm;
            else on_line.pb({b[k],0});
        }

        int wp = 0 , wm = 0;
        rep(k,m){
            int v = A*w[k].x + B*w[k].y + C;

            if(v>0) ++wp;
            else if(v<0) ++wm;
            else on_line.pb({w[k],1});
        }

        if(bp>0 && bm>0) ok = false;
        if(wp>0 && wm>0) ok = false;
        if(bp>0 && wp>0) ok = false;
        if(bm>0 && wm>0) ok = false;

        if(!ok) continue;

        sort(all(on_line));
        int sz = on_line.size();
        int ch = 0;
        rep(k,sz-1) ch += (on_line[k].second != on_line[k+1].second);

        if(ch>1) ok = false;
        if(ok) return true;
    }

    return false;
}

int main(){
    int n,m;
    while(cin >>n >>m,n) cout << (solve(n,m)?"YES":"NO") << endl;
    return 0;
}



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

const int MAX_N = 100;
int N, K;
int plan[MAX_N + 1];
int memo[MAX_N + 1][4][4];
int solve(int n, int b1, int b2){
	if(n == N+1) return 1;
	if(memo[n][b1][b2] != -1) return memo[n][b1][b2];
	if(plan[n] != 0){
		if(b1 == b2 && b1 == plan[n])
			return 0;
		else
			return solve(n+1, plan[n], b1)%10000;
	}
	int t=0;
	for(int i=1; i<=3; ++i){
		if(b1==b2 && b1==i ) continue;
		t+=solve(n+1, i, b1)%10000;
	}
	return memo[n][b1][b2] = t%10000;
}
int main(){
	scanf("%d %d", &N, &K);
	for(int i=0; i<K; ++i){
		int d, k;
		scanf("%d %d", &d, &k);
		plan[d] = k;
	}
	for(int i=0; i<=N; ++i)
		for(int j=0; j<4; ++j)
			for(int k=0; k<4; ++k)
				memo[i][j][k] = -1;
	printf("%d\n", solve(1, 0, 0));
	return 0;
}

Measured memory_bytes: 2688
N,M=map(int,input().split())
L=[]
R=[]
for i in range(M):
    l,r=map(int,input().split())
    L.append(l)
    R.append(r)
count = 0
if min(R)-max(L)+1>=0:
    print(min(R)-max(L)+1)
else:
    print(0)

Measured memory_bytes: 10996
match = [2,5,5,4,5,6,3,7,6]
n,m=map(int,input().split())
aa=list(map(int,input().split()))
dp=[-1]*(n+10)

dp[0]=0
for i in range(n+1):
        for nums in aa:
                if dp[i] == -1 :continue
                dp[i+match[nums-1]] = max(dp[i]*10+nums,dp[i+match[nums-1]])

print(dp[n])

Measured memory_bytes: 14692
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

int main() {
    ll N, T;
    cin >> N >> T;
    ll prev{0}, count{0};
    for (auto &&i: irange(0LL, N)){
        ll t;
        cin >> t;
        count += min(T, abs(t-prev));
        prev = t;
    }
    cout << count+T;
    return 0;
}

Measured memory_bytes: 256
def prepare(n, MOD):
    f = 1
    factorials = [1]
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv

    return factorials, invs


n, k = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()


MOD = 10 ** 9 + 7
facts, invs = prepare(n, MOD)

ans_max = 0
for i in range(k - 1, n):
    ans_max += (arr[i] * facts[i] * invs[k - 1] * invs[i - k + 1]) % MOD

arr.sort(reverse=True)

ans_min = 0
for i in range(k - 1, n):
    ans_min += (arr[i] * facts[i] * invs[k - 1] * invs[i - k + 1]) % MOD

print((ans_max - ans_min) % MOD)

Measured memory_bytes: 21312
#include<stdio.h>
#define MAX 25
#define NIL -1

struct Node{
  int p,l,r;
};
struct Node T[MAX];

void Preorder(int);
void Inorder(int);
void Postorder(int);
 
void Preorder(int u){
  printf(" %d",u);
  if(T[u].l!=NIL){
    Preorder(T[u].l);
  }
  if(T[u].r!=NIL){
    Preorder(T[u].r);
  }
}
 
void Inorder(int u){
  if(T[u].l!=NIL){
    Inorder(T[u].l);
  }
  printf(" %d",u);
  if(T[u].r!=NIL){
    Inorder(T[u].r);
  }
}
 
void Postorder(int u){
  if(T[u].l!=NIL){
    Postorder(T[u].l);
  }
  if(T[u].r!=NIL){
    Postorder(T[u].r);
  }
  printf(" %d",u);
}
 
 
main(){
  int n,i,id,l,r;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    T[i].p=T[i].l=T[i].r=NIL;
  }
  for(i=0;i<n;i++){
    scanf("%d%d%d",&id,&l,&r);
    if(l!=NIL){
      T[l].p=id;
    }
    if(r!=NIL){
      T[r].p=id;
    }
    T[id].l = l;
    T[id].r = r;
  } 
  printf("Preorder\n");
  
  for(i=0;i<n;i++){
    if(T[i].p==NIL){
      Preorder(i);
    }
  }
  printf("\n");
  
  printf("Inorder\n");
  for(i=0;i<n;i++){
    if(T[i].p==NIL){
      Inorder(i);
    }
  }   
  printf("\n");
  
  printf("Postorder\n");
   for(i=0;i<n;i++){
    if(T[i].p==NIL){
      Postorder(i);
    }
  }
   printf("\n");
  return 0;
}

Measured memory_bytes: 616
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;

int main() {
	ll K,sev=0,rep=0;
	cin >> K;
	if (K % 2 == 0) {
		cout << -1 << endl;
		return 0;
	}

	while(rep<=K){
		sev = sev*10 +7;
        sev=sev%K;
		rep++;
		if(sev==0){
			cout << rep << endl;
			return 0;
		}
	}
  cout<<-1<<endl;
}


Measured memory_bytes: 3628
def CountTriangles( A):
	n = len(A);
	A.sort();
	count = 0;
	for i in range(n - 1, 0, -1):
		l = 0;
		r = i - 1;
		while(l < r):
			if(A[l] + A[r] > A[i]):
				count += r - l;
				r -= 1;
			else:
				l += 1;
	print(count);

n = int(input())
a = [ int(i) for i in input().split() ]
CountTriangles(a);


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int h,n,x;
int main()
{
    scanf("%d%d",&h,&n);
    while (n--)
    {
        scanf("%d",&x);
        if (h<=x)
        {
            printf("Yes\n");
            return 0;
        }
        h-=x;
    }
    printf("No\n");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define FORD(x,y,z) for(int x=y;x>=z;x--)
#define MSET(x,y) memset(x,y,sizeof(x))
#define FOR(x,y) for(__typeof(y.begin()) x=y.begin();x!=y.end();x++)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 
void RI(){}
template<typename... T>
void RI( int& head, T&... tail ) {
  scanf("%d",&head);
  RI(tail...);
}
using namespace std;
typedef long long LL;
int main()
{  
	double pi = acos(-1);
	int a, b, h, m;
	cin >> a >> b >> h >> m;
	double t = m * -6.0 * 2.0 * pi / 360.0;
	double mx, my;
	mx = -b * sin(t);
	my = b * cos(t);
	int mm = h * 60 + m;
	t = mm * -0.5 * 2.0 * pi / 360.0;
	double hx, hy;
	hx = -a * sin(t);
	hy = a * cos(t);
//	printf("%f %f %f %f\n", mx, my, hx, hy);
	double ans = sqrt((mx - hx) * (mx - hx) + (my - hy) * (my - hy));
	printf("%.10f\n", ans);

  return 0;
}


Measured memory_bytes: 4120
N = int(input())

odd = []
for i in range(N+1):
    if i % 2 == 1:
        odd.append(i)


ans_odd = []
for i in odd:
    cnt = 0
    for j in range(1, N+1):
        if i % j == 0:
            cnt += 1
    if cnt == 8:
        ans_odd.append(i)

print(len(ans_odd))

Measured memory_bytes: 3060
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

class Comb{
private:
  ll *fac,*finv,*inv;
public:
  Comb(){
    fac = new ll[1000000];
    finv = new ll[1000000];
    inv = new ll[1000000];
    fac[0] = 1;
    for(int i=1;i<1000000;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000000;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000000;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

int main(){
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  for(int i=0;i<n-2;i++){
    if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') ans += 1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
char nextchar(char c,int k){
  rep(i,k){
    if(c=='Z') c='A';
    else c++;
  }
  return c;
}
int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int y=s.size();
  rep(j,y){
    s[j]=nextchar(s[j],n);
  }  
  cout << s << endl;
}


Measured memory_bytes: 256
def main():
    from sys import stdin
    input = stdin.readline
    mod = 998244353
    n = int(input())
    xy = [list(map(int, input().split())) for _ in [0]*n]
    ans = 0
    pow_2 = [1]
    j = 1
    for i in range(n):
        j = j*2 % mod
        pow_2.append(j)
    p2 = pow_2[n-1]

    xy.sort(key=lambda x: x[1])
    xy = [(x, i+1) for i, (x, y) in enumerate(xy)]
    xy.sort()

    class BIT():
        def __init__(self, n):
            self.n = n
            self.maxbit = 2**(len(bin(self.n))-3)
            self.bit = [0]*(self.n+1)
            self.allsum = 0

        # 全ての要素に1を足す
        def all_plus(self):
            self.bit = [0]+[i & (-i) for i in range(1, self.n+1)]
            self.allsum = self.n

        # 要素iにvを追加する
        def add(self, i, v):
            x = i
            self.allsum += v
            while x < self.n + 1:
                self.bit[x] += v
                x += x & (-x)

        # 位置0からiまでの和(sum(bit[:i]))を計算する
        def sum(self, i):
            ret = 0
            x = i
            while x > 0:
                ret += self.bit[x]
                x -= x & (-x)
            return ret

    bit_left = BIT(n)
    bit_right = BIT(n)
    bit_right.all_plus()

    for i, (x, y) in enumerate(xy):
        bit_right.add(y, -1)
        A = bit_left.sum(y)
        B = i-A
        C = bit_right.sum(y)
        D = n-i-1-C
        bit_left.add(y, 1)
        ans += (pow_2[A]-1)*(pow_2[D]-1)*(pow_2[B+C])
        ans += (pow_2[B]-1)*(pow_2[C]-1)*(pow_2[A+D])
        ans -= (pow_2[B]-1)*(pow_2[C]-1)*(pow_2[A]-1)*(pow_2[D]-1)
        ans += p2
        ans = ans % mod
    print(ans)


main()


Measured memory_bytes: 113016
import java.util.Scanner;

public class Main {

		public static void main(String[] args){
			Scanner sc = new Scanner(System.in);
			int A = sc.nextInt();
			int B = sc.nextInt();
			int K = sc.nextInt();
			int k = K - 1;
			if(1 <= A && A <= B && B <= 10*10*10*10*10*10*10*10*10)
			{for(; K > 0;K--) {
				if(1 <= A && A <= B) {
				System.out.println(A);
				A++;}
			}
			for(int i = B - k;i <=B; i++) {
				if(1 <= A && A <= i) {
				System.out.println(i);
				}
			}
			}}}

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

//typedef long long ll;

int main(){
    string S,T;
    cin>>S>>T;
    int ans=0;
    for(int i=0;i<S.size();i++){
        if(S.at(i)==T.at(i)){
            ans++;
        }
    }
    cout<<ans<<endl;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }

  vector<int> B;
  for (int i = 0; i < K; i++) {
    B = vector<int>(N, 0);

    for (int j = 0; j < N; j++) {
      int a = A.at(j); // A_j
      int left = max(j - a, 0);
      int right = min(j + a, N - 1);
      B.at(left)++;
      if (right != N - 1) {
        B.at(right + 1)--;
      }
    }

    for (int j = 1; j < N; j++) {
      B.at(j) += B.at(j - 1);
    }

    if (A == B) {
      break;
    }

    swap(A, B);
  }

  for (int i = 0; i < N; i++) {
    cout << A.at(i);
    if (i == N - 1) {
      cout << endl;
    } else {
      cout << ' ';
    }
  }
}


Measured memory_bytes: 5928
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
typedef long long ll;
using namespace std;

int main(void){
  int n,i,cnt=1;
  string s;
  cin>>n>>s;
  for(i=1;i<n;i++){
    if(s[i]!=s[i-1])cnt++;
  }

  cout<<cnt<<endl;

  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

bool IsComposable(const vector<string>& keys, string &strings, int i) {
	if (i == strings.length()) return true;
	for (string key : keys) {
		if (strings.substr(i, key.length()) == key) return IsComposable(keys, strings,i+ key.length());
	}
	return false;
}

int main() {
	vector<string> keys = { "dream", "dreamer", "erase", "eraser" };
	for (string & key : keys) reverse(key.begin(), key.end());

	string S;
	cin >> S;
	reverse(S.begin(), S.end());
	if (IsComposable(keys, S, 0)) cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 3584
from sys import stdin


def main() -> None:
    a, b = [int(next_str()) for _ in range(2)]
    ans = 0

    for i in range(a, b + 1):
        ans += int(judge(i))

    print(ans)


def judge(a: int) -> bool:
    s = str(a)
    n = len(s)

    for i in range(n // 2):
        if s[i] != s[n - i - 1]:
            return False

    return True


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next()); // リンゴ
        int p = Integer.parseInt(sc.next()); // リンゴの欠片
        p += a * 3; // リンゴ1個からリンゴの欠片3個作成
        int answer = p / 2; // リンゴの欠片2個でアップルパイ1個作成
        System.out.println(answer);
        sc.close();
    }
}

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

struct Unionfind {
  // tree number
  vector<int> par;
  // constructor
  Unionfind(int n = 1) : par(n, -1) {}
  // search root
  int root(int x) {
    if (par[x] < 0) return x;
    return par[x] = root(par[x]);
  }
  // is same?
  bool issame(int x, int y) { return root(x) == root(y); }

  // add
  // already added, return 0
  bool uni(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return 0;
    if (par[x] > par[y]) swap(x, y);
    par[x] += par[y];
    par[y] = x;
    return 1;
  }
  int size(int x) { return -par[root(x)]; }
};

int main() {
  int n, q;
  cin >> n >> q;
  Unionfind uf(n);
  while (q--) {
    int t, u, v;
    cin >> t >> u >> v;
    if (t)
      cout << uf.issame(u, v) << endl;
    else
      uf.uni(u, v);
  }

  return 0;
}

Measured memory_bytes: 3896
n = int(input())
a = list(map(int, input().split()))
s = [0] * n

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

ans = 0
for i in range(1, n):
    ans += a[i] * s[i]

mod = 10**9 + 7

# for i in range(n-1):
#     for j in range(i+1, n):
#         ans += a[i]*a[j]

print(ans%mod)



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

int main() {
    int N, M;
    cin >> N;
    vector<string> R(N),B(M);
    for (int i = 0; i < N; i++){
        cin >> R.at(i);
    }
    cin >> M;
    for (int j = 0; j < M; j++){
        cin >> B.at(j);
    }
    int max = 0;
    for(int i=0;i < N;i++){
        int point = 0;
        for(int j=i;j<N;j++){
            if(R.at(i) == R.at(j)){
                point++;
            }
        }
        for(int k=0;k<M;k++){
            if(R.at(i) == B.at(k)){
                point--;
            }
        }
        if (max < point)
            max = point;
    }
    cout << max <<endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define THE using
#define DARK namespace
#define ONE std
#define dbg(x) cout << #x << " = " << x << endl

THE DARK ONE;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
//    freopen("out.txt", "w", stdout);
//    freopen("input.txt", "r", stdin);
    string str;
    int mi = INT_MAX;
    cin >> str;
    for(int i = 0; i < str.size() - 2; i++){
        int t = stoi(str.substr(i, 3));
        mi = min(mi, abs(t - 753));
    }
    cout << mi << endl;
    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,t=0,x=0,y=0,f=0;
    cin>>n;
    for(int i=0,tt,tx,ty;i<n;i++)
    {
        cin>>tt>>tx>>ty;
        if((abs(tx-x)+abs(ty-y))%2!=(tt-t)%2||abs(tx-x)+abs(ty-y)>(tt-t))
            f=1;
        t=tt,x=tx,y=ty;
    }
    if(!f)cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 3580
#include "iostream"
using namespace std;
int main(){
    long long n,k,a,b;
    cin >>n>>k;
    if (k%2) {
        a=n/k;
        cout <<a*a*a<<endl;
    } else{
        a=n/k;
        b=n/(k/2)-a;
        cout <<a*a*a+b*b*b<<endl;
    }
}


Measured memory_bytes: 256
N,K,Q = map(int, input().split(" ")) #N:参加者 K:ポイント Q:正解数
A = [K]*N

for i in range(0,Q):
    A[int(input())-1] += 1

for point in A:
    if point - Q <= 0 :
        print("No")
    else:
        print("Yes")

Measured memory_bytes: 50872
#include<iostream>
using namespace std;
#define inRange(x,a,b) (a <= x && x < b)
int di[8] = {0,0,1,-1,1,1,-1,-1};
int dj[8] = {1,-1,0,0,1,-1,1,-1};

int h, w, ans;
int mat[20][20];

void dfs(int i, int j, int s){
    if(s >= 10)  return;

    for(int k = 0; k < 4; k++){
        int ni = i+di[k], nj = j+dj[k];
        if(!inRange(ni,0,h) || !inRange(nj,0,w) || mat[ni][nj] == 1)    continue;
        bool valid = true;
        while(mat[ni][nj] != 1){
            if(mat[ni][nj] == 3){
                ans = min(ans, s+1);
                return;
            }
            ni += di[k], nj += dj[k];
            if(!inRange(ni,0,h) || !inRange(nj,0,w)){
                valid = false;
            break;
            }
        }
        if(!valid)  continue;
        mat[ni][nj] = 0;
        dfs(ni-di[k], nj-dj[k], s+1);
        mat[ni][nj] = 1;
    }

}

int main(){
    while(cin >> w >> h, w+h){
        ans = 11;
        int si, sj;
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                cin >> mat[i][j];
                if(mat[i][j] == 2)  si = i, sj = j;
            }
        }
        dfs(si, sj, 0);
        cout << (ans == 11 ? -1 : ans) << endl;
    }
    return 0;
}


Measured memory_bytes: 2964
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <cassert>
#include <random>
using namespace std;
using ll = long long;


int main() {
	int a, b, c; cin >> a >> b >> c;
	map<int, int> cnt;
	cnt[a]++;
	cnt[b]++;
	cnt[c]++;
	for (auto p : cnt) {
		if (p.second == 2) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
x,y=list(map(int,input().split()))
a=[1,3,5,7,8,10,12]
b=[4,6,9,11]
c=2

if x in a and y in a:
    print("Yes")
    exit()

if x in b and y in b:
    print("Yes")
    exit()

if x==c and y==c:
    print("Yes")
    exit()

print("No")


Measured memory_bytes: 3060
//たてH cm よこ W cm の長方形を描くプログラム
#include <stdio.h>

int main()
{
	int i, j;//ループカウンタ
	int H, W;//縦と横
	while (1){//無限ループ
	  scanf("%d %d", &H, &W);
	  if (H == 0) break;
		for (j = 0; j < H; j++){
			for (i = 0; i < W; i++){
				printf("#");
			}
			printf("\n");//改行
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2084
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MOD=1e9+7;
static const ll MAX=101010;

/*
 for(i=0; i<N; i++)
   cin >> a[i];
*/



int main(void) {
  ll i, j, k, l;
  
  ll N;
  cin >> N;
  ll a[MAX];
  
  for(i=0; i<N; i++) cin >> a[i];
  
  
  ll ans=a[0]-1;
  ll h=2;
  for(i=1; i<N; i++) {
    if(a[i]==h) {
      h++;
    }else {
      ans+=(a[i]-1)/h;
    }
  }
  
  pt(ans);
  
  
}




Measured memory_bytes: 1024
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        
        int[] count = new int[100000];
        for(int i=0;i<N;i++) count[sc.nextInt()]++ ;
        
        
        int next = count[0]+count[1]+count[2];
        int ans = next;
        for(int i=3;i<100000;i++){
        	next = next - count[i-3] + count[i];
        	if(ans<next) ans=next;
        }
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 50376
import itertools

n = int(input())
m=a=r=c=h = 0
for i in range(n):
    name = input()
    if name[0] == "M":
        m += 1
    elif name[0] == "A":
        a += 1
    elif name[0] == "R":
        r += 1
    elif name[0] == "C":
        c += 1
    elif name[0] == "H":
        h += 1

s = [m,a,r,c,h]
ans = 0
for v in itertools.combinations(s,3):
    ans += v[0]*v[1]*v[2]

print(ans)






Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main()
{
  int r,g,b,sum,a;
  cin>>r>>g>>b;
  sum=r*100+g*10+b;
  if(sum%4==0)
    cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;
  return 0;
}


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

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var result = 0;
            for (var i = 1; i <= n; i++)
            {
                if ((int) Math.Log10(i) % 2 == 0) result++;
            }
            Console.WriteLine(result);
        }
    }
}

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

#define MAXNUM 200010

using namespace std;

int main(void)
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector<int> subordinates(MAXNUM, 0);
  int num, id;
  cin >> num;
  for (int i = 1; i < num; i++){
    cin >> id;
    subordinates[id]++;
  }
  for (int i = 1; i <= num; i++)
    cout << subordinates[i] << '\n';
  return 0;
}


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

int main(){
    int n,a,b;
    cin >> n >> a >> b;

    int sum = 0;
    int i = 1,k;
    int x,y,z,w;

    while(i < n+1){
        k = i;
        w = k / 10000;
        k -= 10000*w;
        x = k / 1000;
        k -= 1000*x;
        y = k / 100;
        k -= 100 * y;
        z = k / 10;
        k -= 10 * z;
        if(a <= x+y+z+k+w && x+y+z+k+w <= b){
            sum += i;
        }
        i ++;
    }

    cout << sum << endl;
}

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

int main(void){
  int N, K;
  cin >> N >> K;
  int l[K], r[K];
  for(int i = 0; i < K; i++) cin >> l[i] >> r[i];
  
  vector<long long> dp(N+1,0);
  dp[0] = 0;
  dp[1] = 1;
  
  for(int i = 1; i <= N; i++){
    for(int j = 0; j < K; j++){
      if(i - l[j] <= 0) continue;
      dp[i] = (dp[i] + dp[i-l[j]] - dp[max(0,i-r[j]-1)]) % mod;
    }
    dp[i] = (dp[i] + dp[i-1]) % mod;
  }
  
  long long ans = (dp[N] - dp[N-1] + mod) % mod;
  
  cout << ans << endl;
}

Measured memory_bytes: 4820
#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>

using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
    int n, l;
    cin >> n >> l;
    vector<string> s(n);
    REP(i, n) {
        string t;
        cin >> t;
        s[i] = t;
    }

    sort(ALL(s));
    string r = "";
    REP(i, n) {
        r += s[i];
    }
    cout << r << endl;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
A =list(map(int, input().split()))
k = bin(K)[2:]

def add_zero(text):
    if len(text) < len(k):
        mozi = ""
        for i in range(len(k) - len(text)):
            mozi += "0"
        return mozi + text
    else:
        return text

B = [bin(i)[2:] for i in A ]
B = list(map(add_zero, B))

ans_li = []
for index, i in enumerate(k):
    if i == "1":
        str = ""
        for j in range(len(k)-index-1):
            count = 0
            for l in B:
                if l[-j-1] == "1":
                    count += 1
            if count > len(B) - count:
                str = "0" + str
            else:
                str = "1" + str
        ans_li.append(k[:index] + "0" + str)

ans_li.append(k)
ans_li2 = [int("0b"+i, 2) for i in ans_li]
max_score = 0
for i in ans_li2:
    score = 0
    for j in A:
        score += i^j
    max_score = max(score, max_score)

print(max_score)

Measured memory_bytes: 106040
/*
Author: yww
Language: C++
Mail: weeerrr720@qq.com
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<ctime>
#include<functional>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<bitset>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
void open(const char *s){
#ifndef ONLINE_JUDGE
    char str[100];sprintf(str,"%s.in",s);freopen(str,"r",stdin);sprintf(str,"%s.out",s);freopen(str,"w",stdout);
#endif
}
void open2(const char *s){
#ifdef DEBUG
    char str[100];sprintf(str,"%s.in",s);freopen(str,"r",stdin);sprintf(str,"%s.out",s);freopen(str,"w",stdout);
#endif
}
template <class T>
int upmin(T &a, const T &b){return (b<a?a=b,1:0);}
template <class T>
int upmax(T &a, const T &b){return (b>a?a=b,1:0);}
namespace io
{
    const int SIZE=(1<<20)+1;
    char ibuf[SIZE],*iS,*iT;
    char obuf[SIZE],*oS=obuf,*oT=oS+SIZE-1;
    int getc()
    {
        (iS==iT?iS=ibuf,iT=ibuf+fread(ibuf,1,SIZE,stdin):0);
        return iS==iT?EOF:*(iS++);
    }
    int f;
    char c;
    template <class T>
    void get(T &x)
    {
        f=1;
        for(c=getc();(c<'0'||c>'9')&&c!='-';c=getc());
        (c=='-'?f=-1,c=getc():0);
        x=0;
        for(;c>='0'&&c<='9';c=getc())
            x=x*10+c-'0';
        x*=f;
    }
    void flush()
    {
        fwrite(obuf,1,oS-obuf,stdout);
        oS=obuf;
    }
    void putc(char x)
    {
        *(oS++)=x;
        if(oS==oT)
            flush();
    }
    int a[55],t;
    template <class T>
    void put(T x)
    {
        if(!x)
            putc('0');
        x<0?putc('-'),x=-x:0;
        while(x)
        {
            a[++t]=x%10;
            x/=10;
        }
        while(t)
            putc(a[t--]+'0');
    }
    void space()
    {
        putc(' ');
    }
    void enter()
    {
        putc('\n');
    }
    struct flusher
    {
        ~flusher()
        {
            flush();
        }
    }
    io_flusher;
}
const int infi=0x3fffffff;
const ll infll=0x3fffffffffffffffll;
struct info
{
	int x,v,c;
	info(int _1=0, int _2=0, int _3=0):x(_1),v(_2),c(_3){}
};
const int N=200010;
vector<int> g[N];
unordered_map<int,int> h[N];
int c[N];
int m[N];
int n;
void dfs(int x, int fa)
{
	if(x==1)
		m[x]=-1;
	else
	{
		m[x]=max(m[fa],fa);
		h[x][m[x]]=0;
		if(x<m[x]&&m[fa]>x)
			h[x][m[fa]]=0;
	}
	for(auto u:h[x])
		for(int v:g[x])
			if(v<u.first)
				h[v][u.first]=0;
	for(auto v:g[x])
		if(v!=fa)
			dfs(v,x);
	for(auto &u:h[x])
	{
		u.second++;
		for(auto v:g[x])
			if(v<u.first)
				u.second+=h[v][u.first];
	}
	if(x!=1)
	{
		if(x>m[x])
			c[x]+=h[x][m[x]];
		else
		{
			c[x]+=h[x][m[x]];
			if(m[fa]>x)
				c[x]-=h[x][m[fa]];
		}
	}
}
void dfs2(int x, int fa)
{
	c[x]+=c[fa];
	for(auto v:g[x])
		if(v!=fa)
			dfs2(v,x);
}
int main()
{
	open2("AGC029E");
	scanf("%d",&n);
	int x,y;
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&x,&y);
		g[x].push_back(y);
		g[y].push_back(x);
	}
	dfs(1,0);
	dfs2(1,0);
	for(int i=2;i<=n;i++)
		printf("%d ",c[i]);
	return 0;
}

Measured memory_bytes: 60672
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
	string s;
	cin >> s;

	if (s.size() == 26) {
		string t = s;
		if (next_permutation(s.begin(), s.end()) == 0) {
			cout << -1 << endl;
		} else {
			for (int i = 0; i < 26; i++) {
				cout << s[i];
				if (s[i] != t[i]) {
					cout << endl;
					return 0;
				}
			}
			cout << endl;
		}
	} else {
		bool a[26] = {};
		for (int i = 0; i < s.length(); i++) {
			a[s[i] - 'a'] = true;
		}

		for (int i = 0; i < 26; i++) {
			if (!a[i]) {
				s += ('a' + i);
				cout << s << endl;
				return 0;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<stdio.h>
using namespace std;
 
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define INF 1<<25
 
int main()
{
	int n, t, c, x, mx, i, j;
	cin >> n;
	cin >> t;
	mx = INF;
	rep(i, n) {
		cin >> c;
		cin >> x;
		if (t >= x) mx = min(mx, c);
	}
	mx != INF ? cout << mx << endl : cout << "TLE" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main()
{
    string str = "";
    char ch;
    while (cin >> ch, !cin.eof())
    {
        switch (ch)
        {
        case '0':
        case '1':
            str.push_back(ch);
            break;
        case 'B':
            if (!str.empty())
                str.pop_back();
            break;
        }
    }
    cout << str << endl;
    return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define forn(low,high,i) for(i = low;i < high;i++)
#define forrev(high,low,i) for(i = high; i >= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define line cout << __LINE__;
#define prv(a) for(auto x : a) cout << x << ' ';cout << '\n';
#define decimal_digits cout << fixed << setprecision(15);
#define dbg2(a,b) cerr << #a << " = " << a << " " << #b << " = " << b << '\n';        
#define debug(x) cerr << __LINE__ << ' ' << #x << " = " << x << '\n';
#define dln cerr << '\n';
#define dsp cerr << ' ';
#define pln cout << '\n';
#define psp cout << ' ';

typedef unordered_map<int,int> umi;
typedef unordered_map<ll,ll> uml;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const int inf = 1e9;
const ll INF = 1e18;
const ll mod = 1e9 + 7;

clock_t time_p = clock();

void ktj(){
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (float)(time_p)/CLOCKS_PER_SEC << "\n";
}

int main(){
  fastio

  ll n;
  ll i, j, k;

  cin >> n;

  vl a(n + 1);
  forn(0, n + 1, i){
    cin >> a[i];
  }
  vl b(n);
  forn(0, n, i){
    cin >> b[i];
  }

  ll ans = 0;

  forn(0, n, i){
    ll k = min(a[i], b[i]);
    a[i] -= k;
    b[i] -= k;
    ans += k;
    if(b[i]){
      k = min(a[i + 1], b[i]);
      a[i + 1] -= k;
      b[i] -= k;
      ans += k;
    }
  }
  cout << ans << '\n';

  ktj();
}


Measured memory_bytes: 1792
/**
 * C - Slimes
 * https://atcoder.jp/contests/abc143/tasks/abc143_c
 **/
#include<iostream>
#include<string>

using namespace std;

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    int ans = 0;;
    for(int i=0; i<N;i++) {
        for(int j=i+1; j<N; j++) {
            if(S[i]!=S[j]) {
                i=j-1;
                break;
            } else {
                i=j;
            }
        }
        ans += 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNextInt()) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            int x = sc.nextInt();
            int y = sc.nextInt();
            int ans = Integer.MAX_VALUE;
            for (int i = 0; i <= Math.max(x, y) * 2; i++) {
                int remX = Math.max(0, x - i / 2);
                int remY = Math.max(0, y - i / 2);

                ans = Math.min(ans, c * i + remX * a + remY * b);
            }
            System.out.println(ans);
        }
    }
}


Measured memory_bytes: 23252
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<utility>
#include<functional>
#include<stack>
#include<queue>
#include<cmath>

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
# define MOD 1000000000+7
# define INF 1000000000
typedef long long ll;
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }


int main() {

	int a, b;
	cin >> a >> b;
	cout << max(a + a-1, max(b + b-1, a + b)) << endl;

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
// debug
#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl;
#define ddd(x, y, z) cerr << "(" #x "," #y "," #z "):(" << x << "," << y << "," << z << ")" << endl;
#define dump(v) cerr<<#v":[ ";for (auto macro_vi:v){cerr<<macro_vi<< " ";}cerr<<"]"<<endl;
#define ddump(v) cerr<<#v":"<<endl;for(auto macro_row:v) {cerr<<"["; for (auto macro__vi:macro_row){cerr<<macro__vi<< " ";}cerr<<"]"<<endl;}
#define damp(m) for(auto macro_pair:m){cerr<< macro_pair.first<<":"<<macro_pair.second<<endl;}
#define dpair(p) cerr << #p":"<<"(" << p.first << "," << p.second << ")" << endl;
// iterate
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define reprev(i, n) reprrev(i, 0, n)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define all(v) v.begin(), v.end()
// etc
#define chmin(mi, val) mi = min(mi, val);
#define chmax(ma, val) ma = max(ma, val);
using ll = long long;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int l, r;
    cin >> l >> r;

    int mi = 1e9;
    for(ll i=l; i<l+2019; i++){
        for(ll j=i+1; j<i+2019; j++){
            if( (r<=i) or (r<j)){
                continue;
            }
            int now = ((i%2019) * (j%2019))%2019;
            chmin(mi, now)
        }
    }
    cout << mi << endl;
    return 0;
}

Measured memory_bytes: 256