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

using namespace std;
using namespace std;
#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const ll inf = 1e9+7;
const ll mod = 1e9+7;

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

    x*=-1;

    string ans;

    if(a-b>=0)ans="delicious";
    else if(a-b>=x)ans="safe";
    else ans="dangerous";

    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  ll A,B;cin >> A >> B;
  ll e = B*(N-1) + A, s = B + A*(N-1);
  cout << max(0ll,e - s + 1) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(void)
{
  char ch[100];
  int a, n, i, j;
  int t = 0;
  int p = 0;
  scanf("%s", ch);
  n = strlen(ch);

  if(n<4 || n>=11){
    printf("WA");
    return 1;
  }


  if(ch[0] == 'A')
    a = 0;
  else
    a = 1;

  for(i=2;i<=n-2;++i){
    if(ch[i] == 'C'){
      t+=1;
    }
  }

  if(t==1 && a==0){
    for(j=0;j<n;j++){
      if(islower(ch[j]) == 0){
        p+=1;
      }
    }

    if(p==2)
      printf("AC\n");
    else
      printf("WA\n");
  }
  else
    printf("WA\n");



  return 0;



}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int(i)=0; i<(n); i++)
 
int main(){
  int n, a=1;
  cin >> n;
  vector<int> m(n);
  rep(i,n) cin >> m.at(i);
  sort(m.begin(), m.end());
  rep(i, n-1) if(m.at(i) != m.at(i+1)) a++; 
  cout << a;  
}

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

int main(){
  int N; cin>>N;
  
  bool NG=false;
  
  for(int i=0;i<N;i++){
    int t,x,y; cin>>t>>x>>y;
    int d=abs(x)+abs(y);
    if(t<d){
      NG=true;
      break;
    }
    
    else if(t%2!=d%2){
      NG=true;
      break;
    }
    
  }
  
  if(NG)
    cout<<"No"<<endl;
  else
    cout<<"Yes"<<endl;
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            new ABC122().SolveC(new ConsoleInput(Console.In, ' '));
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
  class ABC122
    {
        public void SolveC(ConsoleInput cin)
        {
            var n = cin.ReadInt;
            var q = cin.ReadInt;
            var S = cin.Read.ToCharArray();
            var L = new int[q];
            var R = new int[q];
            for (int i = 0; i < q; i++)
            {
                L[i] = cin.ReadInt - 1;
                R[i] = cin.ReadInt - 1;
            }
            //AC=>10,その他は0に変換
            var temp = new int[n];
            for (int i = 0; i < n; i++)
            {
                if (i == 0) temp[i] = 0;
                else
                {
                    if (S[i] == 'C' && S[i - 1] == 'A') temp[i] = 1;
                    else temp[i] = 0;
                }
            }
            //累積和
            var cumSum = new int[n];
            for (int i = 0; i < n; i++)
            {
                if (i == 0) cumSum[i] = temp[i];
                else cumSum[i] = cumSum[i - 1] + temp[i];
            }
            //foreach (var sum in cumSum) { Write(sum); }
            //WriteLine();
            for (int i = 0; i < q; i++)
            {
               // WriteLine($"L={L[i]} R={R[i]}");
                WriteLine(cumSum[R[i]] - cumSum[L[i]]);
            }
            ReadLine();
        }
    }
}

Measured memory_bytes: 18248
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define sz(c) (int)(c.size())
#define all(c) c.begin(),c.end()
#define ms(a,v) memset(a,v,sizeof(a))
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; }return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; }return 0; }
constexpr ll pow2(const int n) { return 1ll << n; }
constexpr int INF = 1 << 28; constexpr ll LINF = 1ll << 60;
constexpr int MAX = 1e5 + 5; constexpr int MOD = 1e9 + 7; constexpr double EPS = 1e-6;
constexpr int dy[4] = { 0,1,0,-1 }; constexpr int dx[4] = { 1,0,-1,0 };
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

ll modulo_pow(ll x, int n) {
    ll ret = 1;
    while (n > 0) {
        if (n % 2) ret = ret * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return ret;
}

struct Combination_1D {
    vector<ll> nCk;
    ll operator [](const size_t i) { return nCk[i]; }
    void init(const int n) {
        vector<ll> fact(n + 1);
        fact[0] = 1;
        for (int i = 0; i < n; ++i) {
            fact[i + 1] = fact[i] * (i + 1) % MOD;
        }
        vector<ll> ifact(n + 1);
        ifact[n] = modulo_pow(fact[n], MOD - 2);
        for (int i = n; i > 0; --i) {
            ifact[i - 1] = ifact[i] * i % MOD;
        }
        nCk.resize(n + 1);
        for (int i = 0; i <= n; ++i) {
            nCk[i] = fact[n] * ifact[n - i] % MOD * ifact[i] % MOD;
        }
    }
};

int main() {
    int N;
    cin >> N;
    vi A(N + 1);
    vi dup(N + 1, -1);
    int dupl = 0, dupr = 0;
    rep(i, N + 1) {
        cin >> A[i];
        if (dup[A[i]] >= 0) {
            dupl = dup[A[i]];
            dupr = i;
        }
        else {
            dup[A[i]] = i;
        }
    }

    Combination_1D CinAll;
    CinAll.init(N + 1);
    Combination_1D Cex;
    Cex.init(N - dupr + dupl);

    rep(i, 1, N + 2) {
        if (i == 1) write(N);
        else if (N - dupr + dupl < i - 1) {
            ll ans = CinAll[i] % MOD;
            write(ans);
        }
        else {
            ll ans = (CinAll[i] - Cex[i - 1] + MOD) % MOD;
            write(ans);
        }
    }
}

Measured memory_bytes: 5088
#include<iostream>
#include<vector>
#include<cmath>
#include<limits.h>
using namespace std;
int main()
{
	int n,k;
	cin>>n;
	cin>>k;
	vector<int> a(n);
	for(int i=0;i<n;i++)
		cin>>a[i];
	vector<int> dp(n);
	dp[0]=0;
	
	for(int i=1;i<n;i++)
	{
		int min=INT_MAX;
		for(int j=1;j<=k;j++)
		{
			if(i>=j)
			{
				int temp=dp[i-j]+abs(a[i]-a[i-j]);
				if(temp<min)
				{
					
					min=temp;
				}
			}
			else
			{
				break;
			}
		}
		dp[i]=min;
	}
	cout<<dp[n-1];
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main() {
  int N, ans=0, endA=0, beginB=0, same=0; cin >> N;
  for (int i=0; i<N; i++) {
    string S; cin >> S;
    for (int j=0; j<=S.length()-2; j++) {
      if(S[j]=='A'&&S[j+1]=='B') ans++;
    }
    if(S[0]=='B') beginB++;
    if(S[S.length()-1]=='A') endA++;
    if(S[0]=='B'&&S[S.length()-1]=='A') same++;
  }
  if(endA==beginB&&endA==same&&endA!=0) ans += endA-1;
  else ans += min(endA, beginB);
  cout << ans << "\n";
}
      

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
ll MOD = 1e9+7;
void chmin(long long &a, long long b) { if (a > b) a = b; }

int main(){
  ll i, j;
  ll n;
  cin >> n;
  vector<ll> a(n);
  for(i = 0; i < n; i++)
    cin >> a[i];
  sort(ALL(a));
  vector<ll> b(n - 1);
  for(i = 0; i < n - 1; i++)
    b[i] = a[i + 1] - a[i];
  
  //cout << n spa b[0] spa b[1] spa b[2] spa b[3] << endl;
  ll result = 0;
  if(n % 2 == 0){
    for(i = 0; i < n / 2 - 1; i++)
      result += 2 * (i + 1) * b[i];
    
    for(i = 0; i < n / 2 - 1; i++)
      result += 2 * (i + 1) * b[n - i - 2];
    result += b[n / 2 - 1] * (n - 1);
  }
  else{
    for(i = 0; i < n / 2 - 1; i++)
      result += 2 * (i + 1) * b[i];
    for(i = 0; i < n / 2 - 1; i++)
      result += 2 * (i + 1) * b[n - i - 2];
    result += (n - 1) * max(b[n / 2], b[n / 2 - 1]);
    result += (n - 2) * min(b[n / 2], b[n / 2 - 1]);
    
  }  
  cout << result << endl;

  return 0;
}

Measured memory_bytes: 1792
($N,$M,@A)=glob`dd`;$_+=$_<($a=shift@A)&&$M,$s+=$k=$_-$a,$D[$a+2]++,$D[$_+1]-=$k,$D[$_+2]+=$k-1for@B=@A[1..$#A];$c=0,@D=map$c+=$_,@D for a,b;print$s-(sort{$b-$a}map$D[$_]+$D[$_+$M],1..$M)[0]

Measured memory_bytes: 58188
#include <iostream>
#include <queue>
#include <bitset>
using namespace std;

int main(){
	int n, g, b, c, x, y, i, c1, c2;
	char s[20];
	for(; cin >> s, *s - '0';){
		bitset<0xAAAAB> t;
		queue<int> q;
		for( x = n = 0; s[n]; n++ ){
			x |= ( s[n] == 'b' ? 2 : s[n] == 'g' ) << ( 2 * n );
		}
		n *= 2;
		g = 0x55555 & ( 1 << n ) - 1;
		b = 0xAAAAA & ( 1 << n ) - 1;

		q.push(x);
		q.push(-1);
		c = 0;
		for(; q.size() > 1; ){
			x = q.front();
			if( !x || x == g || x == b ){	break;	}
			q.pop();
			if( x == -1 ){	++c;	q.push(-1);	}
			else{
				c1 = x & 3;
				for( i = 2; i < n; i += 2 ){
					c2 = x >> i & 3;
					if( c1 != c2 ){
						y = x & ~( 15 << i - 2 );
						y |= ( 3 - c1 - c2 ) * 5 << i - 2;
						if( !t[y] ){
							t.set(y);
							q.push(y);
						}
					}
					c1 = c2;
				}
			}
		}
		if( q.size() > 1 ){	cout << c << "\n";	}
		else{	cout << "NA\n";	}
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,A=0,B=0;
    cin >> N;
    vector<int> a(N);
    for(int i = 0;i < N;i ++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    for(int i = 0;i < N;i ++){
        if(i%2) B += a[i];
        else A +=a[i];
    }
    cout << A - B << endl;

    return 0;
}

Measured memory_bytes: 256
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include<algorithm>
using namespace std;
int N,M;
char S[60][60];
int main() {
	cin>>N>>M;
	for(int i=0;i<N;i++){
		cin>>S[i];
	}
	int oldW=0,newW=0;
	int oldB=0,newB=0;
	int oldR=100000000,newR=100000000;
	int H=0;
	for(int j=0;j<M;j++){
		if(S[0][j]!='W')H++;
	}
	oldW=H;
	H=0;
	for(int j=0;j<M;j++){
		if(S[1][j]!='W')H++;
	}
	newW=oldW+H;

	H=0;
	for(int j=0;j<M;j++){
		if(S[1][j]!='B')H++;
	}
	newB=oldW+H;

	for(int i=2;i<N;i++){
		oldW=newW;
		oldB=newB;
		oldR=newR;
		H=0;
		for(int j=0;j<M;j++){
			if(S[i][j]!='W')H++;
		}
		newW=oldW+H;
		H=0;
		for(int j=0;j<M;j++){
			if(S[i][j]!='B')H++;
		}
		newB=min(oldW,oldB)+H;
		H=0;
		for(int j=0;j<M;j++){
			if(S[i][j]!='R')H++;
		}
		newR=min(oldR,oldB)+H;
	}


	cout<<newR<<endl;

	return 0;
}

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

int N, t[100][3][2];

signed main()
{
    cin >> N;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 2; k++){
                int a, b;
                cin >> a >> b;
                int c = a * 60 + b;
                t[i][j][k] = c;
                //printf("t[%d][%d][%d]:%d\n", i, j, k, t[i][j][k]);
            }
        }
    }
    int ans = 0;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < 2; j++){
            for(int ii = 0; ii < N; ii++){
                for(int jj = 0; jj < 2; jj++){
                    for(int iii = 0; iii < N; iii++){
                        for(int jjj = 0; jjj < 2; jjj++){
                            int res = 0, sum = 0;
                            int a[3];
                            a[0] = t[i][0][j];
                            a[1] = t[ii][1][jj];
                            a[2] = t[iii][2][jjj];
                            for(int iiii = 0; iiii < N; iiii++){
                                res = 0;
                                for(int jjjj = 0; jjjj < 3; jjjj++){
                                    if(t[iiii][jjjj][0] <= a[jjjj] && a[jjjj] <= t[iiii][jjjj][1]){
                                        res++;
                                    }
                                }
                                if(res == 3){
                                    sum++;
                                }
                            }
                            ans = max(ans, sum);
                        }
                    }
                }
            }
        }
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3088
#include<stdio.h>

int adj[101][101],d[101],n;

void BFS(int now){
	int Q[100000],front,tail, i;
	front=tail=0;

	Q[tail]=now;	++tail;


	while(front!=tail){
		//pop
		now=Q[front];	++front;
		for(i=1;i<=n;i++){
			if(adj[now][i]){
				if(d[i]>=0)continue;

				//push
				Q[tail]=i;	++tail;
				d[i]=d[now]+1;
			}
		}
	}
}

int main(){
	int i,j,u,k,v;

	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d%d",&u,&k);
		d[u]=-1;
		for(j=0;j<k;j++){
			scanf("%d",&v);
			adj[u][v]=1;
		}
	}
	d[1]=0;

	BFS(1);
	for(i=1;i<=n;i++){
		printf("%d %d\n",i,d[i]);
	}

	return 0;
}


Measured memory_bytes: 2032
#define _USE_MATH_DEFINES
#include <iostream>
#include <math.h>
using namespace std;

int main() {
	double r,area,zhou,PI;
	cin >> r;
	PI = M_PI;
	area = PI * r * r;
	zhou = PI * (r * 2);
	printf("%lf %lf",area,zhou);
	return 0;
}

Measured memory_bytes: 3180
def make_2dgrid(g)
  h = g.size
  s = Array.new(h + 1) { Array.new(h + 1, 0) }
  h.times do |i|
    h.times do |j|
      s[i + 1][j + 1] = s[i][j + 1] + s[i + 1][j] - s[i][j] + g[i][j]
    end
  end
  s
end

def query(s, x1, x2, y1, y2)
  s[x2][y2] - s[x1][y2] - s[x2][y1] + s[x1][y1]
end

n, k = gets.split.map(&:to_i)

k2 = 2 * k
gB = Array.new(k2) { Array.new(k2, 0) }
n.times do
  x, y, ci = gets.split
  x = x.to_i % k2
  y = (y.to_i + (ci == "W" ? k : 0)) % k2
  gB[x][y] += 1
end
ans = 0

sB = make_2dgrid(gB)

sBk2 = sB[k2]
sBk20 = sBk2[0]
sB0 = sB[0]
sB00 = sB0[0]
k.times do |i|
  sBi = sB[i]
  sBik = sB[i + k]
  sBik0 = sBik[0]
  sBik2 = sBi[k2]
  sBk2k2 = sBk2[k2]
  sB0k2 = sB0[k2]
  sBikk2 = sBik[k2]
  sBi0 = sBi[0]
  k.times do |j|
    ikjk = sBik[j + k]
    score = sBi[j] - sB0[j] - sBi0 + sB00
    score += sBk2[j] - sBik[j] - sBk20 + sBik0
    score += ikjk - sBi[j + k] - sBik[j] + sBi[j]
    score += sBik2 - sB0k2 - sBi[j + k] + sB0[j + k]
    score += sBk2k2 - sBikk2 - sBk2[j + k] + ikjk
    ans = score if score > ans
    score = n - score
    ans = score if score > ans
  end
end
p ans


Measured memory_bytes: 64764
#include <bits/stdc++.h>
typedef long long  ll;
#define press_F_to_pay_respect ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn for(int i=0;i<n;i++) 
#define form for(int j=0;j<n;j++) 
#define fora(i,a,b) for(int i = a; i < (b); i++)
#define pb push_back 
#define pob pop_back()
#define mp make_pair 
#define sc second 
#define f first 
#define kek cout<<endl; 
#define all(v) ((v).begin()), ((v).end()) 
#define pob pop_back() 
#define halt {cout<<"No"; return 0;}
const ll MOD = 1e9 + 7;
const int N = 200005;
const int INF = 1e8;
const ll MOD1=998244353;
using namespace std;

int main()
{
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
 press_F_to_pay_respect;
 // cout << fixed << setprecision(12) << ans;
ll a,b,c;
cin>>a>>b>>c;
ll t=a;
a=max(0ll,a-c);
if(a==0)
{
          c-=t;
          cout<<a<<" "<<max(0ll,b-c);
}
else 
{
          cout<<a<<" "<<b;
          
}
return 0;
 

}

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

int main()
{
  int n, c1=0;
  cin>>n;
  for(int i=1; i<10; i++)
  {
    for(int j=1; j<10; j++)
    {
      if(i*j == n)
      {
        c1=1;
        break;
      }
    }
    if(c1==1)
        break;
  }
  if(c1==1)
    cout<<"Yes";
  else
    cout<<"No";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;
int divr[maxn];
/*ll modexpo(ll a,ll b)
{
     ll res=1LL;
     while(b>0)
     {
          if(b&1)res=(res*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return res;
}
void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}*/
 
















int ct[100005][2];
int main()
{
     int n;
     cin>>n;
     vector<int> a(n),b(n);rep(i,n)cin>>a[i];
     b=a;
     sort(b.begin(),b.end());
     int l=n/2-1;
     for(int i=0;i<n;i++)
     {
          if(a[i]<=b[l])cout<<b[l+1];
          else cout<<b[l];
          cout<<"\n";
     }
     
     
}




















 

Measured memory_bytes: 3712
// inputに入力データ全体が入る
function Main(input) {
	var ans = 0
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.trim().split("\n");
	// s = input[0].split(' ').map((n) => (parseInt(n)))
	var s = 'abcdefghijklmnopqrstuvwxyz'
	var idx = s.indexOf(input[0])
	ans = s.substr(idx + 1, 1)



	//出力
	console.log(ans)
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
// Main(require('fs').readFileSync('./input.txt', 'utf-8'));

Measured memory_bytes: 21064
#include <stdio.h>
	int main()
	{
	// R = Display Rating
	// N = Participated in Contest
	// I = Inner Rating
	int N, R, I;
	scanf("%d %d", &N, &R);
	if (N<10){
		I=100*(10-N);
		printf("%d", R+I);
	} else {
		printf("%d", R);
	}
	return 0;
	}

Measured memory_bytes: 2156
#include <iostream>
#include <string>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#define ll long long
using namespace std;

string n;

int main()
{
   cin>>n;
   if(n[n.length()-1]=='3')
    cout<<"bon"<<endl;
   else if(n[n.length()-1]=='0'||n[n.length()-1]=='1'||n[n.length()-1]=='6'||n[n.length()-1]=='8')
    cout<<"pon"<<endl;
   else
    cout<<"hon"<<endl;
   return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

const int INF = 1e9+5;

int main(){
    int k;
    cin >> k;
    ll res = 0;
    for(int a=1;a<=k;a++){
      for(int b=1;b<=k;b++){
        for(int c=1;c<=k;c++){
          int tmp = gcd(a,b);
          res += gcd(tmp,c);
        }
      }
    }
   cout << res <<endl;
}

Measured memory_bytes: 3636
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int D = sc.nextInt();
        
        boolean flg = false;
        while (true) {
            
            C = C - B;
            if (C <= 0) {
                flg = true;
                break;
            }
            
            A = A - D;
            if (A <= 0) {
                break;
            } 
        }
        
        if (flg) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
        
    }
}


Measured memory_bytes: 35872
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, k; cin >> n >> k;
  vector<ll> A(n);
  vector<ll> neg, pos;
  ll zero = 0;
  rep(i, n) {
    cin >> A[i];
    if(A[i] < 0) neg.push_back(A[i]);
    else if(A[i] == 0) zero++;
    else pos.push_back(A[i]);
  }
  sort(all(neg));
  sort(all(pos));
  ll nneg = 1LL * neg.size() * pos.size();
  ll nzero = zero * (n-1) - zero * (zero-1) / 2;
  if(k <= nneg) {
    k--;
    auto count = [&](ll t) {
      assert(t < 0);
      ll cnt = 0;
      for(ll ne: neg) {
        cnt += end(pos)-lower_bound(all(pos), (abs(t)+abs(ne)-1)/abs(ne));
      }
      return cnt;
    };
    auto bsearch = [&]() {
      auto test = [&](ll t) {
        return count(t) <= k;
      };
      ll ok = -longinf, ng = 0;
      while(abs(ok-ng) > 1) {
        ll mid = (ok+ng)/2;
        (test(mid) ? ok : ng) = mid;
      }
      return ok;
    };
    ll ret = bsearch();
    cout << (count(ret) < k+1 ? ret+1 : ret) << endk;
  } else if(k <= nneg+nzero) {
    cout << 0 << endk;
  } else {
    ll rem = k-(nneg+nzero)-1;
    for(ll& ne: neg) ne *= -1;
    reverse(all(neg));
    auto count = [&](ll t) {
      assert(t > 0);
      ll cnt = 0;
      rep(i, neg.size()) {
        auto itr = upper_bound(all(neg), t/neg[i]);
        cnt += max((int(itr-begin(neg))-i-1), 0);
      }
      rep(i, pos.size()) {
        auto itr = upper_bound(all(pos), t/pos[i]);
        cnt += max((int(itr-begin(pos))-i-1), 0);
      }
      return cnt;
    };
    auto bsearch = [&]() {
      auto test = [&](ll t) {
        return count(t) <= rem;
      };
      ll ok = 1, ng = longinf;
      while(abs(ok-ng) > 1) {
        ll mid = (ok+ng)/2;
        (test(mid) ? ok : ng) = mid;
      }
      return ok;
    };
    ll ret = bsearch();
    cout << (count(ret) < rem+1 ? ret+1 : ret) << endk;
  }
  return 0;
}


Measured memory_bytes: 6768
#include<iostream>
#include<cmath>
#include<algorithm>

using namespace std;

typedef long long ll;

int Q;

int main() {
	cin >> Q;
	for (int i = 0; i < Q; i++) {
		ll A, B;
		cin >> A >> B;
		if (A > B)swap(A, B);
		if (A == B) {
			cout << (A - 1) * 2 << endl;
		}
		else if (A + 1 == B) {
			cout << (A - 1) * 2 << endl;
		}
		else {
			ll root = sqrt(A * B - 1);
			if (root * root > A * B - 1)root--;
			if (root * (root + 1) < A * B) {
				cout << root * 2 - 1 << endl;
			}
			else {
				cout << root * 2 - 2 << endl;
			}
		}

	}
	return 0;
}

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

int main() {
  int N, o;
  vector<int> a;

  cin >> N;

  while (cin >> o) {
    a.push_back(--o);
  }

  int i = 0, c = 0;

  while (true) {
    if (i == 1) {
      cout << c << endl;
      break;
    }

    if (c >= N) {
      cout << -1 << endl;
      break;
    }

    c++;
    i = a.at(i);
  }
}


Measured memory_bytes: 892
k,n = map(int, input().split())
al = list(map(int, input().split()))
al.sort()

ans = 10**18
for start_i in range(n):

    if start_i == 0:
        clock = al[-1] - al[0]
    else:
        clock = k - al[start_i] + al[start_i-1]

    if start_i == n-1:
        c_clock = al[-1] - al[0]
    else:
        goal = start_i+1
        c_clock = al[start_i] + (k-al[goal]) 

    ans = min(ans, clock, c_clock)
    # print(clock)
    # print(c_clock)

print(ans)

Measured memory_bytes: 100664
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  ll sum = 0;
  sum += min(a, k);
  k -= min(a, k);
  k -= min(b, k);
  sum -= min(c, k);
  k -= min(c, k);
  cout << sum << '\n';
  assert(k == 0);
  
  return 0; 
}


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

bool harshad(int n){
    int digitSum=0;
    int num=n;
    while(n>0){
        digitSum+=n%10;
        n/=10;
    }
    if(num%digitSum==0) return true;
    else return false;
}

int main(){
    int N;
    cin>>N;
    if(harshad(N)) printf("Yes");
    else printf("No");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

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

    vector<int> l(n);

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

    sort(l.begin(), l.end());

    if (accumulate(l.begin(), l.begin() + (n - 1), 0) > l.back()) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

#define P 1000000007

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}

char a[200001], b[200001];
int main(void){
	int n, i, j;
	scanf("%d", &n);
	for(i=1; i<=n; i++){
		int A;
		scanf("%d", &A);
		a[i]=A;
	}
	int ans=0;
	for(i=n; i>0; i--){
		int c=a[i];
		for(j=i*2; j<=n; j+=i){
			c+=b[j];
		}
		if((c&1)!=0){
			b[i]=1;
			ans++;
		}else{
			b[i]=0;
		}
	}
	printf("%d\n", ans);
	for(i=1; i<=n; i++){
		if(b[i]!=0)
			printf("%d ", i);
	}
	putchar(10);
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ll_s long
#define mod 1000000007
#define forn(i,start,lim) for(ll i=start;i<lim;i++)
#define forn_d(i,start,lim) for(ll i=start;i>=lim;i--)
#define f first
#define s second
#define pb push_back
#define pf push_front
#define mp make_pair
#define debug1(a) cout<<"------\n"<<#a<<" = "<<a<<endl<<"------"<<endl
#define debug2(a,b) cout<<"--------------\n"<<#a<<" = "<<a<<" ; "<<#b<<" = "<<b<<endl<<"--------------"<<endl
#define debug3(a,b,c) cout<<"----------------------\n"<<#a<<" = "<<a<<" ; "<<#b<<" = "<<b<<" ; "<<#c<<" = "<<c<<endl<<"----------------------"<<endl
#define sz(a) (ll)(a.size())
#define debug4(a) cout<<"chu "<<a<<endl
#define endl "\n"

ll fn(ll i, ll alreadysmall, ll rem, string &s, ll n, ll d, vector<vector<vector<ll>>> &memo){
  // if(i==n)
    // debug3(i,alreadysmall,rem);
  if(i==n){
    if(rem == 0)
      return 1;
    else
      return 0;
  }


  if(memo[i][rem][alreadysmall] != -1){
    // debug3(i,alreadysmall,rem);
    return memo[i][rem][alreadysmall];
  }
  ll ans = 0;
  if(alreadysmall == 1){
    forn(j,0,10){
      ans = (ans + fn(i+1,1,(rem+j)%d,s,n,d,memo))%mod;
    }
    // debug3(i,alreadysmall,ans);
  }else{
    ll cur_digit = s[i] - '0';
    forn(j,0,cur_digit){
      ans = (ans + fn(i+1,1,(rem+j)%d,s,n,d,memo))%mod;
    }
    ans = (ans + fn(i+1,0,(rem+cur_digit)%d,s,n,d,memo))%mod;
  }
  return memo[i][rem][alreadysmall] = ans;
}

int main()
{
  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  ll t;
  // cin>>t;
  t=1;
  while(t--){
    string s;
    cin>>s;
    ll d, n = s.size();
    cin>>d;
    vector<vector<vector<ll>>> memo(n,vector<vector<ll>>(d,vector<ll>(2,-1)));
    ll ans = 0;
    ll cur_0 = s[0]-'0';
    forn(i,0,cur_0)
      ans = (ans + fn(1,1,i%d,s,n,d,memo))%mod;

    ans = (ans + fn(1,0,cur_0%d,s,n,d,memo))%mod;
    ans = (ans-1+mod)%mod;
    cout<<ans<<endl;
  }
  return 0;
}


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

using namespace std;

int main() {
	string S;
	cin >> S;
	int ans = 0;
	for (int i = 0; i < S.size() / 2; i++) {
		if (S[i] != S[S.size() - 1 - i])ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBUG = true;

int main(){

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

    int n;
    cin >> n;
    for (size_t i = 0; i < n; i++){
        int num;
        cin >> num;
        for (size_t i1 = 0; i1 < 3; i1++){
            for (size_t i2 = 0; i2 < 3; i2++){
                if( a[i1][i2] == num ) a[i1][i2] = 0;
            }
        }
    }
    
    bool flag = false;
    for(int i = 0; i < 3; i++){
        if( a[i][0] == a[i][1] && a[i][1] == a[i][2] ) flag = true;
    }

    for(int i = 0; i < 3; i++){
        if( a[0][i] == a[1][i] && a[1][i] == a[2][i] ) flag = true;
    }

    if( a[0][0] == a[1][1] && a[1][1] == a[2][2] ) flag = true;
    if( a[0][2] == a[1][1] && a[1][1] == a[2][0] ) flag = true;

    if(flag){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(void){
    int N,X,count,min,sum=0;
    scanf("%d %d",&N,&X);
    count = N;
    int m[N];
    for(int i=0; i<N; i++){
        scanf("%d",&m[i]);
    }

    min = m[0];
    for(int i=0; i<N; i++){
        sum += m[i];
        if(min > m[i]) min = m[i];
    }

    X = X - sum;
    count = count + X / min;

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

    return 0;
}

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

using namespace std;

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

  string s;
  cin >> s;
  string res;
  for (auto &c : s) {
    if (c != 'B') 
      res += c;
    else if (res.size() > 0)
      res = res.substr(0, res.size()-1);
  }
  cout << res << endl;

  return 0;
}



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


using namespace std;

long long maxim = 1e18;

int main(){
  long long N;
  long long A[100010];
  for(int i=0;i<100010;i++){
    A[i] = 0;
  }
  double keta=0;
  long long mul=1;
  bool ok = true;
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> A[i];
    if(A[i]==0){
      cout << 0 << endl;
      return 0;
    }
  }
  for(int i=0;i<N;i++){
    mul*=A[i];
    keta+=log(A[i])/log(10);
    if(keta>18 || mul > maxim){
      ok = false;
      break;
    }
  }

  if(ok){
    printf("%18lld\n",mul);
  }else{
    cout << -1 << endl;
  }

  return 0;
}


Measured memory_bytes: 4664
#from scipy.misc import comb
N = int(input())

if N <= 9:
  print(0)
  exit(0)
  
P = {}
for i in range(2,N+1):
  work = i
  for j in range(2,i+1):
    while work % j == 0:
      if not j in P:
        P[j] = 1
      else:
        P[j] += 1
      work = work // j
      #print(work,j,i)
    if work == 1:
      break
      
#(74)(24,2)と(14,4)と(4,4,2)が取れればそれが答え
# a:2, b:4, c:14, d:24, e:74
a,b,c,d,e = 0,0,0,0,0
for k,v in P.items():
  if v >= 2:
    a += 1
  if v >= 4:
    b += 1
  if v >= 14:
    c += 1
  if v >= 24:
    d += 1
  if v >= 74:
    e += 1
#print(P)
#print(a,b,c,d,e)
print(b*(b-1)*(a-2) // 2 + (c * (b-1) if b > 0 else 0) + (d * (a-1) if a > 0 else 0) + e)

Measured memory_bytes: 3064
import math
import string
import itertools
import fractions
import heapq
import collections
import re
import array
import bisect
import sys
import random
import time
inf = 10**9


def main():
    n = int(input())
    minv = int(input())
    maxv = -inf

    for i in range(n-1):
        x = int(input())
        maxv = max(maxv, x-minv)
        minv = min(minv, x)

    print(maxv)


if __name__ == '__main__':
    main()



Measured memory_bytes: 8996
#include<map>
#include<stack>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<complex>
#include<iostream>
#include<assert.h>
#include<algorithm>
using namespace std;
#define pb push_back
#define inf 1001001001
#define infll 1001001001001001001LL
#define FOR0(i,n) for(int (i)=0;(i)<(n);++(i))
#define FOR1(i,n) for(int (i)=1;(i)<=(n);++(i))
#define mp make_pair
#define pii pair<int,int>
#define ll long long
#define ld double
#define vi vector<int>
#define SZ(x) ((int)((x).size()))
#define fi first
#define se second
#define RI(n) int (n); scanf("%d",&(n));
#define RI2(n,m) int (n),(m); scanf("%d %d",&(n),&(m));
#define RI3(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k));
template<typename T,typename TT> ostream& operator<<(ostream &s,pair<T,TT> t) {return s<<"("<<t.first<<","<<t.second<<")";}
template<typename T> ostream& operator<<(ostream &s,vector<T> t){FOR0(i,sz(t))s<<t[i]<<" ";return s; }
#define dbg(vari) cerr<<#vari<<" = "<<(vari)<<endl
#define all(t) t.begin(),t.end()
#define FEACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define TESTS RI(testow)while(testow--)
#define FORZ(i,a,b) for(int (i)=(a);(i)<=(b);++i)
#define FORD(i,a,b) for(int (i)=(a); (i)>=(b);--i)
#define gmax(a,b) (a)=max((a),(b))
#define gmin(a,b) (a)=min((a),(b))
#define ios0 ios_base::sync_with_stdio(0)
using namespace std;

int main(){
	ll n,x;
	cin>>n>>x;
	ll a=x,b=n-x,ans=n;
	for(;;){
		if(a<b)swap(a,b);
		if(!(a%b)){
			ans+=(a/b*2-1)*b;
			break;
		}
		ans+=(a/b)*2*b; 
		a%=b;
	}	
	cout<<ans;
}


Measured memory_bytes: 256
use proconio::marker::{Chars};
use proconio::input;
use std::collections::HashSet;

fn main() {
  input! {
    n: usize,
    s: Chars
  };
  
  let mut max: usize = 0;
  for i in 0..=n {
    
    let mut x: HashSet<char> = HashSet::new();
    for j in 0..i {
      x.insert(s[j]);
    }
    
    let mut y: HashSet<char> = HashSet::new();
    for j in i..n {
      y.insert(s[j]);
    }
    
    let intersection: HashSet<_> = x.intersection(&y).collect();
    let size = intersection.iter().count();
    if max < size {
      max = size;
    }
  }
  
  println!("{}", max);
}

Measured memory_bytes: 2200
#include<cstdio>
#include<bitset>
#include<iostream>
using namespace std;
const int NN=2000+11;
int a[NN]={};
bitset<NN*NN> b;
int main(){
	int n;
	scanf("%d",&n);
	int s=0;
	for(int i=1;i<=n;++i){
		scanf("%d",&a[i]);
		s+=a[i];
	}
	b[0]=1;
	for(int i=1;i<=n;++i){
		b=b|(b<<(a[i]));
	}
	for(int i=(s+1)/2;i<=s;++i){
		if(b[i]){
			printf("%d\n",i);
			return 0;
		}
	}
}

Measured memory_bytes: 2176
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<utility>
#include<queue>
#include<tuple>
#include<stdio.h>
#define rep(i, n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int n, r;
	cin>>n>>r;
	if(10<=n){
		cout<<r<<endl;
	}
	else{
		cout<<100*(10-n)+r<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import sys
from heapq import*
def g(s,g):
 F=[1e7]*-~n;F[s]=0
 H=[(0,s)]
 while H:
  c,u=heappop(H)
  if u==g:return c
  for f,v in E[u]:
   t=c+f
   if t<F[v]:
    F[v]=t
    heappush(H,(t,v))
 return-1
for e in iter(input,'0 0'):
 n,k=map(int,e.split())
 E=[[]for _ in[0]*-~n]
 for _ in[0]*k:
  f=input()
  if'0'==f[0]:print(g(*map(int,f[2:].split())))
  else:
   c,d,e=map(int,f[2:].split())
   E[c]+=[(e,d)];E[d]+=[(e,c)]


Measured memory_bytes: 6084
#include <bits/stdc++.h>
 
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
 
typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
 
const ll e5 = 1 << 20;
const ll mod = 998244353;
const ll e3 = 1 << 13;
const ll INF = 1ll << 60;
 
int main() {
  int n, a, b;
  cin >> n >> a >> b;

  if (n * a > b) {
    cout << b << endl;
  } else {
    cout << n * a << endl;
  }
  return 0;
}

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

string str;
int ans[26];
int main() {
	memset(ans, 1, sizeof(ans));
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> str;
		int cnt[26] = { 0, };
		for (int j = 0; j < str.size(); j++) {
			cnt[str[j] - 'a']++;
		}
		for (int j = 0; j < 26; j++)ans[j] = min(ans[j], cnt[j]);
	}
	string t;
	for (int i = 0; i < 26; i++) {
		while (ans[i]) {
			--ans[i];
			t = t + (char)('a' + i);
		}
	}
	cout << t;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int N, T, S, s[2][3000];
int dp[3001][3001];

int dfs(int n, int t){
  //  printf("%d %d\n", n,t);
  if(n == N) return 0;
  if(dp[n][t] != -1) return dp[n][t];
  int res = 0;
  res = max(res, dfs(n+1, t));
  if(!(t <= S && t + s[1][n] > S) && s[1][n] + t <= T) res = max(res, dfs(n+1, t + s[1][n]) + s[0][n]);
  else if(t <= S && t + s[1][n] > S && S + s[1][n] <= T) res = max(res, dfs(n+1, S + s[1][n]) + s[0][n]);

  return dp[n][t] = res;
}

int main(){
  scanf("%d%d%d", &N, &T, &S);
  rep(i, N) scanf("%d%d", &s[0][i], &s[1][i]);
  memset(dp, -1, sizeof(dp));
  printf("%d\n", dfs(0, 0));
  return 0;
}

Measured memory_bytes: 36536
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        ArrayList<Integer> ary = new ArrayList<>();
        for(int i=0; i<N; i++){
            ary.add(scanner.nextInt());
        }
        ArrayList<Integer> cp = new ArrayList<>(ary);
        quickSort(cp);

        Integer max = cp.get(0);
        for(int i=0; i<N; i++){
            if(ary.get(i) == max){
                System.out.println(cp.get(1));
            }else{
                System.out.println(max);
            }
        }
    }

    public static void swap(ArrayList<Integer> ary, int i, int j){
        Integer tmp = ary.get(i);
        ary.set(i, ary.get(j));
        ary.set(j, tmp);
    }

    public static int selectPivotIndexRondomly(int left, int right){
        Random rand = new Random();
        return rand.nextInt(right-left+1)+left;
    }

    public static void _quickSort(ArrayList<Integer> ary, int left,int right){
        if(left>=right){return;}
        int pivotIndex = selectPivotIndexRondomly(left, right);
        Integer pivot = ary.get(pivotIndex);
        int l=left, r=right;
        while(l<=r){
            while(ary.get(l)>pivot){l++;}
            while(ary.get(r)<pivot){r--;}
            if(l<=r){
                swap(ary, l, r);
                l++; r--;
            }
        }
        _quickSort(ary, left, r);
        _quickSort(ary, l, right);
    }
    public static void quickSort(ArrayList<Integer> ary){
        int l = 0;
        int r = ary.size() - 1;
        _quickSort(ary, l, r);
    }
}


Measured memory_bytes: 96344
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vp;
typedef map<ll, ll> mll;
typedef map<string, ll> mstrll;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fir first
#define sec second
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
#define out(x) cout << (x)
#define indent() cout << '\n'
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
ll gcd(ll a, ll b){return b != 0 ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}
const ll INF = 1e16;
const ll MOD = 1e9 + 7;
ll a, b, c, n, m, x, y, z, w, h, ans, mx, mn;
string s, t;
vll dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
//vll dx = {-1, 0, 1, -1, 1, -1, 0, 1}, dy = {-1, -1, -1, 0, 0, 1, 1, 1};
string alphabet = "abcdefghijklmnopqrstuvwxyz";

bool graph[8][8], visited[8] = {true};

int dfs(ll v, ll n){
	bool all_visited = true;
    rep(i, n){
		if(visited[i] == false)
			all_visited = false;
	}
	if(all_visited){
		return 1;
	}
	ll ret = 0;
	rep(i, n){
		if(graph[v][i] == false) continue;
		if(visited[i]) continue;

		visited[i] = true;
		ret += dfs(i, n);
		visited[i] = false;
	}
	return ret;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> n >> m){
        mll cnt;
        rep(i, m){
            cin >> a >> b;
            graph[a - 1][b - 1] = graph[b - 1][a - 1] = true;
        }
        print(dfs(0, n));
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int compare_int(const void *a, const void *b)
{
//    return *(int*)a - *(int*)b;
    return *(long long*)a - *(long long*)b;
}
//  qsort(A, b, sizeof(int), compare_int);

long long  factorial(long long n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}

int main()
{
//  int a ,b, c, d, e, X, Y;
  long long  a, b, c, d, e, X, Y;
  //  double  c;
//  int  A[200003]={};
  long long  A[100003]={};
//  long long  B[100003]={};
  int  C[100003][11]={};

  int  flag[1003]={};

//  long long  a, b, c, d, X, Y;
  char s[101][101]={};
  char t[101]={};
//  int N, M;
//  int A[1000000001]={};
//  long long  C[101]={};
  int i,j,k;
  long long p,q;
//  int flag=0;
//  int tmp=0;
  char tmp[101]={};
  long long min=10000000000;
//  long long min=100000001;
  int len=0;
  int l=0;
  int r=1000001;
  int cnt=1;
  int num=1;
  int num1=0;
  int num2=0;
  long long ans=1;
  int max=0;
  int addr=0;
  int ptn=0;
//  bool on_off[100]={};
  
//  char alp[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

  //  a=0;
//  scanf("%lld %lld", &a, &b);
//  scanf("%d%d", &a,&c);
//  cnt = strlen(t);
// printf("%d\n",a);
  for(i=0;i<4;i++){
    scanf("%c", &t[i]);
    if(t[i-1]==t[i]){
      printf("Bad\n");
      return 0;
    }
  }
    
  printf("Good\n");
  

    
//    printf("%s %d %d\n", s[i],C[i][0],C[i][1]);
   // printf("%d\n", C[i][1]);
/*  for(i=0;i<addr;i++){
//  scanf("%lld%lld", &B[0][i],&B[1][i]);
//    ans=ans+A[i];
    printf("%lld ", A[i]);
  }
*/
//    printf("%d ", cnt);
   
//  ans=a*3;
//  ans=(ans+b)/2;
//  printf("%d\n", ans);

  
//  printf("%lf\n",ans);
  //  //  if(flag==0)   printf("TLE\n");
//    if(max < cnt - max)  printf("Yes\n");
//    else  printf("No\n");
  
return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr_inv(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define rep(i,n) repr(i,0,n)
#define MOD 1000000007
#define PI 3.1415926535
using namespace std;
int main(void)
{
	int n, ans=-1;

	cin>>n;

	vector<int> a(n), c(100002, 0), sum(100001);

	rep(i, n) cin>>a[i];

	rep(i, n) c[a[i]]++;

	rep(i, 100001){
		if(i==0){
			sum[i]=c[i]+c[i+1];
		}else{
			sum[i]=c[i-1]+c[i]+c[i+1];
		}
	}

	rep(i, 100001){
		if(ans<sum[i]) ans=sum[i];
	}
	cout<<ans<<endl;

}

Measured memory_bytes: 1408
n, *abc = gets.split.map(&:to_i)
ls = n.times.map{gets.to_i}

ans = 10**18
(4**n).times do |i|
  arr = Array.new(3){[]}

  n.times do |j|
    if i%4 < 3
      arr[i%4].push(ls[j])
    end
    i /= 4
  end

  next if arr.any?{|a| a.size == 0}
  mp = 0
  3.times do |k|
    mp += (arr[k].size - 1 ) * 10
    mp += (abc[k] - arr[k].inject(:+)).abs
  end
  ans = mp if ans > mp
end
p ans


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
using st = size_t;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using ull = unsigned long long;
#define inf 0x40000000
#define all(v) v.begin(), v.end()
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
template <typename T> using mptr = T*;

int main(){
	int n,l;
	cin>>n>>l;
	vector<string> s(n);
	rep(i,n)cin>>s.at(i);
	sort(all(s));
	rep(i,n)cout<<s.at(i);
	cout<<"\n"s;
}

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

int main() {
	int n, a, b, ans = 0;
	cin >> n >> a >> b;
	for (int i = 1; i <= n; i++) {
		int sum = i / 10000 + (i / 1000 - (i / 10000) * 10) + (i / 100 - (i / 1000) * 10) + (i / 10 - (i / 100) * 10) + i % 10;
		if (a <= sum && sum <= b)ans += i;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256