akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j,k;
  int a[22][22],m,n,w,h,x,y,vx,vy;
  char c;
  cin>>n;
  for(i=0;i<n;i++){
    cin>>h>>w;
    memset(a,-1,sizeof(a));
    for(j=1;j<h+1;j++){
      for(k=1;k<w+1;k++){
	cin>>c;
	if(0){
	}else if(c=='.'){
	  a[k][j]=0;
	}else if(c=='*'){
	  a[k][j]=-2;
	}else if(c=='#'){
	  a[k][j]=-1;
	}else if(c=='-'){
	  a[k][j]=-3;
	}else if(c=='^'){
	  a[k][j]=0;
	  x=k;
	  y=j;
	  vx=0;
	  vy=-1;
	}else if(c=='v'){
	  a[k][j]=0;
	  x=k;
	  y=j;
	  vx=0;
	  vy=1;
	}else if(c=='<'){
	  a[k][j]=0;
	  x=k;
	  y=j;
	  vx=-1;
	  vy=0;
	}else if(c=='>'){
	  a[k][j]=0;
	  x=k;
	  y=j;
	  vx=1;
	  vy=0;
	}
      }
    }
    cin>>m;
    for(j=0;j<m;j++){
      cin>>c;
      if(0){
      }else if(c=='U'){
	vx=0;
	vy=-1;
	if(a[x+vx][y+vy]==0){
	  x+=vx;
	  y+=vy;
	}
      }else if(c=='D'){
	vx=0;
	vy=1;
	if(a[x+vx][y+vy]==0){
	  x+=vx;
	  y+=vy;
	}
      }else if(c=='L'){
	vx=-1;
	vy=0;
	if(a[x+vx][y+vy]==0){
	  x+=vx;
	  y+=vy;
	}
      }else if(c=='R'){
	vx=1;
	vy=0;
	if(a[x+vx][y+vy]==0){
	  x+=vx;
	  y+=vy;
	}
      }else if(c=='S'){
	for(k=1;;k++){
	  if(0){
	  }else if(a[x+vx*k][y+vy*k]==-1){
	    break;
	  }else if(a[x+vx*k][y+vy*k]==-2){
	    a[x+vx*k][y+vy*k]=0;
	    break;
	  }
	}
      }
    }
    for(j=1;j<h+1;j++){
      for(k=1;k<w+1;k++){
	if(0){
	}else if(k==x&&j==y){
	  if(0){
	  }else if(vx==-1&&vy==0){
	    cout<<'<';
	  }else if(vx==0&&vy==-1){
	    cout<<'^';
	  }else if(vx==1&&vy==0){
	    cout<<'>';
	  }else if(vx==0&&vy==1){
	    cout<<'v';
	  }
	}else if(a[k][j]==0){
	  cout<<'.';
	}else if(a[k][j]==-2){
	  cout<<'*';
	}else if(a[k][j]==-1){
	  cout<<'#';
	}else if(a[k][j]==-3){
	  cout<<'-';
	}
      }
      cout<<endl;
    }
    if(i!=n-1)
      cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

typedef long long ll;

const ll MOD = 1e9 + 7;

class FDistinctNumbers {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int N;
	    in >> N;
	    vector<int> A(N);
	    REP(i,0,N) in >> A[i];

	    vector<int> cnt(N+1);
	    REP(i,0,N) cnt[A[i]]++;
	    sort(all(cnt), greater<int>());
	    cnt.resize(distance(lower_bound(cnt.rbegin(), cnt.rend(), 1), cnt.rend()));
	    sort(all(cnt));

	    vector<int> cntSum(cnt.size());
	    cntSum[0] = cnt[0];
	    REP(i,1,cnt.size()) cntSum[i] = cntSum[i-1] + cnt[i];

	    int maxK = 1;
	    RREP(x,1,N+1) { // Xがxのときの最大のK // Kが小さいとXは大きい
	        const auto itr = upper_bound(all(cnt), x);
	        const int index = distance(cnt.begin(), itr);
	        int K = (index > 0 ? cntSum[index-1] : 0) + (cnt.size() - index) * x;
	        K /= x;
	        while (maxK <= K && K > 0) {
                out << x << "\n";
                maxK++;
            }
	    }
	    while (maxK <= N) {
	        out << 0 << "\n";
	        maxK++;
	    }
	    // answer: Kがkのときの最大のX
	}
};


signed main() {
	FDistinctNumbers solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 4224
a,b = map(int,input().split())
N = input()
p = 1
for i in range(a):
    if N[i] == "-":
        p = 0
    elif N[i] == "0" or "1" or "2" or "3" or "4" or "5" or "6" or "7" or "8" or "9":
        p = p
    else:
        p = 0
if N[a] == "-":
    p = p
else:
    p = 0
for j in range(b):
    if N[a+1+j] == "-":
        p = 0
    elif N[a+1+j] == "0" or "1" or "2" or "3" or "4" or "5" or "6" or "7" or "8" or "9":
        p = p
    else:
        p = 0

    
if p == 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <string.h>
using namespace std;

int main()
{
  char wed[3];
  int i;
  int sum=0,max=0;
  cin >> wed;
  for(i=0; i<3; i++)
  {
    if(wed[i] == 'R')
    {
      sum++;
    }
    else if(wed[i] == 'S')
    {
      sum = 0;
    }
    if(max < sum) max = sum;
  }
  
  cout << max << endl;
  return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

const int64 mod = 1e9+7;

int32 find(int32 x){
	FOR(i, 1, x+1){
		if(i*(i+1)/2 == x) return i;
	}
	return -1;
}

int main(void){
	int32 N;
	cin >> N;
	int32 x = find(N);
	vector<vector<int32>> v;
	if(x == -1){
		cout << "No" << endl;
		return 0;
	}
	int32 now = 1;
	REP(i, x){
		v.push_back(vector<int32>());
		REP(j, i+1){
			v[i].push_back(now++);
		}
	}
	cout << "Yes" << endl << x+1 << endl;
	REP(i, x){
		int32 px = 0, py = i;
		cout << x << " ";
		while(px < i+1){
			cout << v[py][px++] << " ";
		}
		px--;
		py++;
		while(py < x){
			cout << v[py++][px] << " ";
		}
		cout << endl;
	}
	cout << x << " ";
	REP(i, x) cout << v[i][i] << " ";
	cout << endl;
}


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

using namespace std;

using i64 = int64_t;

const i64 MOD = 1e9+7;

const i64 INF = 1e18+7;


signed main(){
    i64 n;
    cin >> n;
    vector<i64> a(n);
    multiset<i64> s;
    for(auto& x : a){
        cin >> x;
        s.insert(x);
    }
    i64 ans = 0;

    auto del = [&](i64 x){
        auto it = s.find(x);
        if(it != s.end())
            s.erase(it);
    };

    while(!s.empty()){
        i64 x = *prev(s.end());
        i64 z = 1;
        while(x >= z)
            z <<= 1;
        i64 y = z - x;
        del(x);
        auto it = s.find(y);
        if(it != s.end()){
            ++ans;
            s.erase(it);
        }
    }
    cout << ans << endl;
}


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

int main(){
    int array[4][2] = {0};
    int hit = 0;
    int blow = 0;
    while (cin>>array[0][0]>>array[1][0]>>array[2][0]>>array[3][0]){
        cin >> array[0][1]>>array[1][1]>>array[2][1]>>array[3][1];
        hit = 0;
        blow = 0;
        for (int i = 0; i < 4; i++){
            if (array[i][0] == array[i][1]) {
                hit++;
            }
        }
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                if (array[i][0] == array[j][1]) {
                    if (array[i][0] != array[i][1]) {
                        blow++;
                    }
                }
            }
        }
        cout << hit << " " << blow << endl;
        //printf("%d %d\n",hit,blow);
    }
    return 0;
}

Measured memory_bytes: 1160
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,cc,n) for(int i=cc;i<(n);++i)
#define dreps(i,cc,n) for(int i=cc;i>(n);--i)
#define llreps(i,cc,n) for(long long i=cc;i<(n);++i)
#define ALL(v) begin(v),end(v)
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;

int main()
{
	int n,ans = 0;
	cin >> n;
	int syo = n / 1000;
	int mod = n % 1000;
	if (mod > 0)
		++syo;
	ans = syo * 1000 - n;

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

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string s = "ai1333";
    rep(i,n/100){
        s += "3";
    }
    cout << s << "\n";
    return 0;
}



Measured memory_bytes: 3204
S = input()

if(S=='SUN'):
    print(7)
elif(S=='MON'):
    print(6)
elif(S=='TUE'):
    print(5)
elif(S=='WED'):
    print(4)
elif(S=='THU'):
    print(3)
elif(S=='FRI'):
    print(2)
elif(S=='SAT'):
    print(1)


Measured memory_bytes: 3060
n_num = int(input())
n_list = list(map(int, input().split()))
q_num = int(input())
q_list = list(map(int, input().split()))

count = 0
for q in q_list:
	lower = 0
	higher = len(n_list) - 1
	m = (higher - lower) // 2

	while lower <= higher:
		if n_list[m] == q:
			count += 1
			break
		elif n_list[m] > q:
			higher = m - 1
			m = lower + (higher - lower) // 2
		else:
			lower = m + 1
			m = lower + (higher - lower) // 2

print(count)


Measured memory_bytes: 16704
N = int(input())
H = list(map(int, input().split()))
S = [0 for i in range(N)]
res = 0
for h in range(100,0, -1):
    tmp = False
    for i in range(N):
        if H[i] >= h:
            tmp = True
        elif tmp:
            res += 1
            tmp = False
    if tmp:
        res += 1
print(res)

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

using namespace std;
using namespace boost;

main(){
    constexpr auto M = 1000000007;

    int64_t n;
    cin >> n;

    vector<int64_t> c(n);
    for (auto&& cc : c) {
        cin >> cc;
    }

    vector<int64_t> last(200001L, -1);
    vector<int64_t> counts(n + 1);
    counts[0] = 1;
    for (auto i : irange(0L, n)) {
        auto cc = c[i];

        counts[i + 1] = counts[i];
        auto ll = last[cc];
        if (ll >= 0 && ll + 1 < i) {
            counts[i + 1] += counts[ll + 1];
            counts[i + 1] %= M;
        }

        last[cc] = i;
    }

    cout << counts.back() << endl;
}

Measured memory_bytes: 4992
//https://yukicoder.me/problems/25
//https://yukicoder.me/submissions/194289
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <string>
#include <string.h>
using namespace std;

const int MAX_N=10000;
int w;

int main(){
	cin >> w;
	
	cout << w*32 << endl;
	return 0;
}

Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define ms(x,y) memset(x, y, sizeof(x))
#define lowbit(x) ((x)&(-x))
#define sqr(x) ((x)*(x))
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;


void run_case() {
    int a, b, x;
    cin >> a >> b >> x;
    double theta;
    if(a*a*b<= 2*x)
        theta = atan(2.0*(a*a*b-x) / (double)(a*a*a));
    else
        theta = acos(-1.0)/2.0-atan(2.0*x/(double)(b*b*a));
    cout << 180.0*theta/acos(-1.0);
}


int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cout.flags(ios::fixed);cout.precision(9);
    //int t; cin >> t;
    //while(t--)
    run_case();
    cout.flush();
    return 0;
}


Measured memory_bytes: 4112
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,d,x,t[11][11];
main(){
  cin>>n>>d>>x;
  r(i,d)r(j,n)cin>>t[i][j];
  r(i,d-1){
    int dp[x+1]={},p=x+1;
    r(j,n)r(k,p)if(k-t[i][j]>=0)dp[k]=max(dp[k],dp[k-t[i][j]]+t[i+1][j]);
    r(j,p)x=max(x,dp[j]+p-1-j);
  }
  cout<<x<<endl;
}

Measured memory_bytes: 3208
module CountingSort
	def counting_sort a, k
		n = a.size
		c = Array.new(k + 1){0}
		b = Array.new(k + 1){nil}
		n.times do |j|
			c[a[j]] += 1
		end

		1.upto k do |i|
			c[i] = c[i] + c[i - 1]
		end

		(n-1).downto 0 do |j|
			b[c[a[j]]] = a[j]
			c[a[j]] -= 1
		end
		return b.compact
	end
module_function :counting_sort
end

include CountingSort

n = gets.to_i
num = gets.split.map(&:to_i)
puts counting_sort(num, 2_000_000).join(" ")

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

typedef long long ll;

int N;
int A[200005];
int X;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N;
    for (int i=0; i<N; i++){
        cin >> A[i];
        X ^= A[i];
    }
    for (int i=0; i<N; i++) cout << (X ^ A[i]) << ' ';
    cout << endl;
}

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

using namespace std;

int main()
{
    int H, W;
    vector<string> S;

    cin >> H >> W;

    for(int i=0; i<H; i++){
        string Si;

        cin >> Si;

        S.push_back(Si);
    }

    // 全体を検索
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            // 点を見つける
            if(S[i][j] == '.'){
                int num = 0;
                // 周辺を検索
                for(int x=-1; x<=1; x++){
                    for(int y=-1; y<=1; y++){
                        if(0<=(i+x) && (i+x)<H
                        && 0<=(j+y) && (j+y)<W){
                            if(S[i+x][j+y]=='#'){
                                num++;
                            }
                        }

                        string numStr = to_string(num);
                        S[i][j] = numStr[0];
                    }
                }
            }
        }
    }

    for(int i=0; i<H; i++){
        cout << S[i] << endl;
    }
}

Measured memory_bytes: 256
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
					/*多倍長整数/cpp_intで宣言
					#include <boost/multiprecision/cpp_int.hpp>
					using namespace boost::multiprecision;
					*/

#pragma gcc target ("avx2")
#pragma gcc optimization ("o3")
#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2.0)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define addf(T) [](T a, T b){return (a + b);}
#define minf(T) [](T a, T b){return min(a, b);}
#define maxf(T) [](T a, T b){return max(a, b);}
#define nof(T) [](T a){return a;}


using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const long double PI = acos(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

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

ll lcm(ll number1, ll number2) {
	return number1 / gcd(number1, number2) * number2;
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	int n;
	scanf("%d", &n);
	int a;
	bool b = true;
	rep(i, n) {
		scanf("%d", &a);
		if (a % 2 == 0) {
			if (a % 3 != 0 && a % 5 != 0)b = false;
		}
	}
	printf("%s\n", b ? "APPROVED" : "DENIED");

	Please AC;
}


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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

i64 remove(i64 b,i64 i){
    return b&~(1<<i);
}

void solve(){
    i64 N;
    cin >> N;

    vector<i64> A(1<<N);
    rep(i,0,1<<N) cin >> A[i];

/*
    vector<i64> dp1(1<<N),dp2(1<<N);
    rep(i,1,1<<N){
        dp2[i]=A[i];
        rep(j,0,N){
            if((i&(1<<j))==0) continue;
            i64 k=remove(i,j);
            dp1[i]=max(dp1[i],dp1[k]);
            dp1[i]=max(dp1[i],dp2[k]+A[i]);
            dp2[i]=max(dp2[i],dp2[k]);
        }
    }
*/
    vector<vector<pair<i64,int>>> dp(1<<N);
    dp[0].push_back(make_pair(A[0],0));
    i64 ans=0;
    rep(i,1,1<<N){
        dp[i].push_back(make_pair(A[i],i));
        rep(j,0,N){
            if((i&(1<<j))==0) continue;
            i64 k=remove(i,j);
            rep(i2,0,min(2,(int)dp[k].size())){
                bool f=true;
                for(const auto& p:dp[i]) if(p==dp[k][i2]){
                    f=false;
                    break;
                }
                if(f) dp[i].push_back(dp[k][i2]);
            }
        }
        sort(rbegin(dp[i]),rend(dp[i]));
        while(dp[i].size()>2) dp[i].pop_back();
        ans=max(ans,dp[i][0].first+dp[i][1].first);
        cout << ans << endl;
    }
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 119296
#include<iostream>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF=2e18;
string A,B;
typedef string::const_iterator SC;
ll NumParse(SC& it){
    it++;
    ll ret=0;
    while(isdigit(*it)){
        ret*=10;
        ret+=*it-'0';
        it++;
    }
    return ret;
}
string Func(ll al, ll ar,ll bl,ll br){
    //cout<<"ok"<<endl;
    ll rootA;
    ll rootBeginA;
    ll rootEndA;
    ll lCount=0;
    ll rCount=0;
    for(ll i=al;i<=ar;i++){
        if(A[i]=='('){
            lCount++;
        }else if(A[i]==')'){
            rCount++;
        }else if(A[i]=='['){
            if(lCount==rCount){
                SC sc=A.begin()+i;
                rootBeginA=i;
                rootA = NumParse(sc);
                rootEndA=sc-A.begin();
                break;
            }
        }
    }
    ll rootB;
    ll rootBeginB;
    ll rootEndB;
    lCount=0;
    rCount=0;
    for(ll i=bl;i<=br;i++){
        if(B[i]=='('){
            lCount++;
        }else if(B[i]==')'){
            rCount++;
        }else if(B[i]=='['){
            if(lCount==rCount){
                SC sc=B.begin()+i;
                rootBeginB=i;
                rootB = NumParse(sc);
                rootEndB=sc-B.begin();
                break;
            }
        }
    }
    string ret="";
    if((A[rootBeginA-2]=='(' && A[rootBeginA-1]==')') || (B[rootBeginB-2]=='(' && B[rootBeginB-1]==')')){
        ret+="()";
    }else{
        ret+='(';
        ret+=Func(al+1,rootBeginA-2,bl+1,rootBeginB-2);
        ret+=')';
    }
    ret+="["+to_string(rootA+rootB)+"]";
    if((A[rootEndA+1]=='(' && A[rootEndA+2]==')') || (B[rootEndB+1]=='(' && B[rootEndB+2]==')')){
        ret+="()";
    }else{
        ret+='(';
        ret+=Func(rootEndA+2,ar-1 ,rootEndB+2,br-1);
        ret+=')';
    }
    return ret;
}

int main(){
    cin>>A;
    cin>>B;
    cout<<Func(0,A.length()-1,0,B.length()-1)<<endl;

    return 0;
}


Measured memory_bytes: 3280
using namespace std;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    int n;
    cin >> n;
    vector<int> a;
    int x;
    for (int i = 0; i < n; i++){
        cin >> x;
        a.push_back(x);
    }
    sort(all(a));

    int sum1=0,sum2=0;
    for (int i = 0; i < n; i++){
        if (i % 2 == 0){
            sum1 += a.back();
            a.pop_back();
        } else {
            sum2 += a.back();
            a.pop_back();
        }
    }
    cout << sum1 - sum2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
//#include <iomanip>
#include <stdlib.h>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(),z.end())
#define rsort(z) sort(z.rbegin(),z.rend())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())
#define ccnt(z,w) count(z.begin(),z.end(),w)


void printVec(std::vector<int> & vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec2(std::vector<Int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a / gcd(a, b) *b;
	//a*bは64bit integer overflow
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

string gen(int num) {
	string str = "";
	for (int i = 0; i < num; i++) str += ".";
	return str;
}
Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}


int main() {
	//int a, b,c; cin >> a >>b;
	string s; cin >> s;
	if (s[0] == '9' || s[1] == '9')cout << "Yes";
	else cout << "No";
	


	cout << endl;
	return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(i,s,n) for(int i = (s); i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) v.begin(),v.end()
const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    while(1){
        string s;
        cin>>s;
        if(s=="0") break;
        ll ans=0;
        rep(i,s.size()) ans+=s[i]-'0';
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3180
n = int(input())
S = input()
NE = [0 for i in range(n)]
NE[0] = 1 if S[0] == "W" else 0
for i in range(1,n):
    NE[i] = NE[i-1] + (1 if S[i] == "W" else 0)
#print(NE)
ans = 10**10
for i in range(n):
    nw = NE[i-1] if i>0 else 0
    ne = n-i-(NE[n-1]-nw) + (-1 if S[i]=="E" else 0)
    ans = min(ans, nw+ne)
print(ans)


Measured memory_bytes: 62308
#include <stdio.h>
int main(void){   
int a,b;   
char op;       
while(1){   
scanf("%d %c %d", &a, &op, &b);   
if( op == '?')break;     
if ( op == '+' )    
printf("%d\n",(a+b));    
else if ( op == '-' )    
printf("%d\n",(a-b));    
else if ( op == '*' )    
printf("%d\n",a*b);    
else if ( op == '/' )    
printf("%d\n",a/b);} 
return 0;}


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

int main(){
  ll n,k;
  cin >> n >> k;
  ll mod_0 = 0, mod_half = 0;
  for(ll i=1;i<=n;i++){
    if(i%k==0) mod_0++;
    if(k%2==0 && i%k==k/2) mod_half++;
  }
  cout << mod_0*mod_0*mod_0 + mod_half*mod_half*mod_half << endl;
  return 0;
}


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

int main(){
  
  int n;cin>>n;
  int arr[n];
  for(int i=0;i<n;i++){
    cin>>arr[i];
  }
int dp[n];
  memset(dp,-1,sizeof(dp));
  
  dp[0]=0;
  dp[1] = abs( arr[0] -arr[1] );
  
  for(int i=2;i<n;i++){
     dp[i] = min( dp[i-2] +abs(arr[i]-arr[i-2]) , dp[i-1] +abs(arr[i]-arr[i-1]) );
  }
  
  cout<<dp[n-1]<<"\n";
  
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void) {
   int a,b,c,d,e,f,g,h;
   scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
   if (a<=b && b<=c){
   	f=a;
    } else if (a<=c && c<=b){
   	f=a;
    } else if (b<=c && c<=a){
   	f=b;
    } else if (b<=a && a<=c){
   	f=b;
   	} else if (c<=a && a<=b){
   	f=c;
   	} else if (c<=b && b<=a){
   	f=c;
   	}
   	if(d<=e){
   		g=d;
   	} else if(e<=d){
   		g=e;
   	}
    h=f+g-50;
    printf("%d\n",h);
	return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>

using namespace std;

int main(){
   int n,a,b;
   cin>>n>>a>>b;
   if(a+b>=n){
      cout<<min(a,b)<<" "<<a+b-n<<endl;
   }
   else cout<<min(a,b)<<" "<<0<<endl;

   
}

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

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

  int l = 0, r = 1e6;

  rep(i, m)
  {
    int left, right;
    cin >> left >> right;
    r = min(r, right);
    l = max(l, left);
  }

  if (l <= r)
  {
    cout << r - l + 1;
  }
  else
  {
    cout << 0;
  }

}


Measured memory_bytes: 3596
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>

#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>

#include <cmath>
#include <numeric>
#include <random>
#include <cstring>
#include <cassert>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

// type
#include <cstdint>
#include <functional>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
template <class T> using MaxHeap = priority_queue<T>;
template <class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* ---------- Functions */
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int N;
    cin >> N;
    bool yes = false;
    if (N % 10 == 7) yes = true;

    N /= 10;
    if (N % 10 == 7) yes = true;

    N /= 10;
    if (N % 10 == 7) yes = true;

    if (yes) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
typedef long long LL;
using namespace std;

int main() {
  LL n, m;
  cin >> n >> m;
  vector<LL> a(n);
  for (int i = 0; i < n; i ++) {
    cin >> a[i];
    a[i] %= m;
  }

  vector<LL> dp(n + 1);
  map<LL, LL> mp;
  for (int i = 1; i <= n; i ++) {
    dp[i] = (dp[i - 1] + a[i - 1]) % m;
    mp[dp[i]] ++;
  }

  LL ans = 0;
  for (auto x : mp) {
    ans += (x.second * (x.second - 1)) / 2;
    if (x.first == 0) ans += x.second; 
  }

  cout << ans << endl;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}
const int INF = 1<<30;
const int MOD = 1000000007;
int dx[4] = {0,0,-1,1};
int dy[4] = {-1,1,0,0};

struct edge{
  int to;
  int id;
};

int n;
vector<edge> g[100005];
vector<int> color;
int k = 0;

void dfs(int now,int p = -1,int c = -1){
  int to_c = 0;
  for(auto e:g[now]){
    if(e.to == p) continue;
    if(c == to_c) to_c++;
    color[e.id] = to_c;
    chmax(k,to_c);
    dfs(e.to,now,to_c);
    to_c++;
  }
}

int main(){
  cin >> n;
  color.resize(n-1,-1);
  
  rep(i,n-1){
    int a,b; cin >> a >> b;
    a--,b--;
    edge ea,eb;
    ea.to = b; ea.id = i;
    eb.to = a; eb.id = i;
    g[a].push_back(ea);
    g[b].push_back(eb);
  }

  dfs(0);

  cout << k+1 << endl;
  rep(i,n-1){
    cout << color[i]+1 << endl;
  }
  return 0;
}

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

using namespace std;
int main()
{
  int n;
  scanf("%d",&n);
  int a[n],i;
  for(i=0;i<n;++i)
       scanf("%d",&a[i]);
  
  sort(a,a+n);
  printf("%d",a[n-1]-a[0]);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ls (o<<1)
#define rs (o<<1|1)
#define pb push_back
const double PI= acos(-1.0);
const int M = 2e5+7;
/*
int head[M],cnt=1;
void init(){cnt=1,memset(head,0,sizeof(head));}
struct EDGE{int to,nxt,w;}ee[M*2];
void add(int x,int y,int w){ee[++cnt].nxt=head[x],ee[cnt].w=w,ee[cnt].to=y,head[x]=cnt;}
*/
char a[M],b[M];
int main()
{
	ios::sync_with_stdio(false);
  	cin.tie(0);
  	cin>>a>>b;
  	int n=strlen(a);
  	int nm=0;
  	for(int i=0;i<n;i++)
  	{
  		if(a[i]!=b[i])nm++;
	  }
	  cout<<nm<<endl;
	return 0;
}

Measured memory_bytes: 4000
#include<iostream>
#include<algorithm>
#include<string>
std::string S;
int ans=1<<30;
int main(){
    std::cin>>S;
    ans=S.size();
    for(int i=1;i<S.size();i++){
        if(S[i-1]!=S[i]){
            ans=std::min(ans,std::max(i,(int)S.size()-i));
        }
    }
    std::cout<<ans<<std::endl;
    return 0;
}

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

using namespace std;

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

typedef long long ll;

bool chck(vector<int> p){
    vector<int> cp(p);
    sort(cp.begin(),cp.end());
    if(p==cp) return true;
    else return false; 
}
bool tmp(vector<int> p, int i, int j){
    int tmp = p[i];
    p[i] = p[j];
    p[j] = tmp;
    if(chck(p))return true;
    else return false;
}
int main() {
    int N;
    cin >> N;
    vector<int> p(N);
    rep(i,N) cin >> p[i];
    rep(i,N){
        rep(j,N){
            if(tmp(p, i, j)){
                cout<<"YES"<<endl;
                return 0;
            }
        }
    }
    cout<<"NO"<<endl;
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import deque
mod=10**9+7
n=int(input())
edges=[[] for _ in range(n)]
for _ in range(n-1):
    x,y=map(int,input().split())
    edges[x-1].append(y-1)
    edges[y-1].append(x-1)
children=[[] for _ in range(n)]
V=[]
q=deque([0])
used=[False]*n
used[0]=True
while q:
    par=q.popleft()
    C=children[par]
    V.append(par)
    for v in edges[par]:
        if used[v]:
            continue
        C.append(v)
        used[v]=True
        q.append(v)
DP=[None for _ in range(n)]
for par in V[::-1]:
    white,black=1,1
    for v in children[par]:
        w,b=DP[v]
        white*=w+b
        white%=mod
        black*=w
        black%=mod
    DP[par]=(white,black)
print(sum(DP[0])%mod)

Measured memory_bytes: 75952
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long double a,b,c;
	cin>>a>>b>>c;
	if(c-a-b>0&&4*a*b<(c-a-b)*(c-a-b)) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3704
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define MKP make_pair

const int N=6e2+5;
int n,D1,D2,lim,qaq1,qaq2;
int col1[N][N],col2[N][N],vis[N][N],set[N][N],flag[N*N];
vector <pair <int,int> > T1,T2;
vector <pair <int,int> > G[N][N]; 

template <typename _Tp> inline void IN(_Tp&x) {
	char ch;bool flag=0;x=0;
	while(ch=getchar(),!isdigit(ch)) if(ch=='-') flag=1;
	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	if(flag) x=-x;
}

void dfs1(int x,int y,int now,int cnt) {
	col1[x][y]=now,set[x][y]=cnt,(now==1)?++qaq1:++qaq2;
	for(pair <int,int> v:G[x][y])
		if(!col1[v.first][v.second]) dfs1(v.first,v.second,3-now,cnt);
}
void dfs2(int x,int y,int now,int cnt) {
	col2[x][y]=now,set[x][y]=cnt,(now==1)?++qaq1:++qaq2;
	for(pair <int,int> v:G[x][y])
		if(!col2[v.first][v.second]) dfs2(v.first,v.second,3-now,cnt);
}

inline bool check(int x,int y) {return (x>0&&y>0&&x<=lim&&y<=lim);}
int main() {
	IN(n),IN(D1),IN(D2),lim=n<<1;
	for(int i=0;i<=lim;++i)
		for(int j=0;j<=lim;++j) {
			if(i*i+j*j==D1) T1.push_back(MKP(i,j));
			if(i*i+j*j==D2) T2.push_back(MKP(i,j));
		}
	for(int x=1;x<=lim;++x)
		for(int y=1;y<=lim;++y)
			for(pair <int,int> now:T1) {
				int dx=now.first,dy=now.second;
				if(check(x+dx,y+dy)) G[x][y].push_back(MKP(x+dx,y+dy));
				if(check(x-dx,y+dy)) G[x][y].push_back(MKP(x-dx,y+dy));
				if(check(x+dx,y-dy)) G[x][y].push_back(MKP(x+dx,y-dy));
				if(check(x-dx,y-dy)) G[x][y].push_back(MKP(x-dx,y-dy));
			}
	int cnt=0;
	for(int x=1;x<=lim;++x)
		for(int y=1;y<=lim;++y) if(!col1[x][y]) {
			qaq1=0,qaq2=0,dfs1(x,y,1,++cnt);
			if(qaq1<qaq2) swap(qaq1,qaq2),flag[cnt]=true;
		}
	for(int x=1;x<=lim;++x)
		for(int y=1;y<=lim;++y)
			if(flag[set[x][y]]) col1[x][y]=3-col1[x][y];
	for(int x=1;x<=lim;++x)
		for(int y=1;y<=lim;++y)
			G[x][y].clear();
	for(int x=1;x<=lim;++x)
		for(int y=1;y<=lim;++y)
			for(pair <int,int> now:T2) {
				int dx=now.first,dy=now.second;
				if(check(x+dx,y+dy)) G[x][y].push_back(MKP(x+dx,y+dy));
				if(check(x-dx,y+dy)) G[x][y].push_back(MKP(x-dx,y+dy));
				if(check(x+dx,y-dy)) G[x][y].push_back(MKP(x+dx,y-dy));
				if(check(x-dx,y-dy)) G[x][y].push_back(MKP(x-dx,y-dy));
			}
	cnt=0;
	memset(set,0,sizeof(set)),
	memset(flag,0,sizeof(flag));
	for(int x=1;x<=lim;++x)
		for(int y=1;y<=lim;++y) if(!col2[x][y]) {
			qaq1=0,qaq2=0,dfs2(x,y,1,++cnt);
			if(qaq1<qaq2) swap(qaq1,qaq2),flag[cnt]=true;
		}
	for(int x=1;x<=lim;++x)
		for(int y=1;y<=lim;++y)
			if(flag[set[x][y]]) col2[x][y]=3-col2[x][y];
	cnt=0;
	for(int x=1;x<=lim;++x)
		for(int y=1;y<=lim;++y)
			if(col1[x][y]==col2[x][y]&&col2[x][y]==1) {
				printf("%d %d\n",x-1,y-1),++cnt;
				if(cnt>=n*n) return 0;
			}
	return 0;
}

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

int main(){
  int N, x;
  cin >> N >> x;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
      cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  int res = 0;
  for (int i = 0; i < N; i++) {
    x -= vec.at(i);
    if(x < 0){
    	break;
    }
    res++;
  }
  if(x > 0){
  	res--;
  }
  cout << res << endl;
}


Measured memory_bytes: 256
// 2011/02/26 Tazoe

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
	while(true){
		double a, b, c, d;
		cin >> a >> b >> c >> d;
		if(a==-1.0&&b==-1.0&&c==-1.0&&d==-1.0)
			break;

		a = a*M_PI/180.0;
		b = b*M_PI/180.0;
		c = c*M_PI/180.0;
		d = d*M_PI/180.0;

		double x = acos(sin(a)*sin(c)+cos(a)*cos(c)*cos(d-b));

		cout << (int)(6378.1*x+0.5) << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
//#include "ext/pb_ds/assoc_container.hpp"
//#include "ext/pb_ds/tree_policy.hpp"
//using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define int long long
#define pb push_back
#define fi first
#define se second
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define IO ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pii pair<int,int>
#define sz(x) (int)x.size()
const int mod = 1e9 + 7;
//const int mod1 = 998244353;
typedef long double f80;

#ifndef LOCAL
#pragma GCC optimize ("O2")
#define endl '\n'
#endif

//template<typename T>
//using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
//
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//int rand(int l, int r){
//    uniform_int_distribution<int> uid(l, r);
//    return uid(rng);
//}

ll pwr(ll a,ll b, ll mod){
    a %= mod;
    ll ans = 1;
    while(b){
        if(b & 1) ans = (ans * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return ans;
}

string to_string(string s) {
    return '"' + s + '"';
}

string to_string(const char* s) {
    return to_string((string) s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

const int N = 1e5 + 5;
int x[N];
const int LOGN = 18;
int dp[LOGN][N];

void solve(){
    int n, l, q;
    cin >> n;
    fr(i, 1, n) {
        cin >> x[i];
    }
    cin >> l >> q;
    int pt = 1;
    fr(i, 1, n) {
        while(pt + 1 <= n && x[pt + 1] - x[i] <= l) {
            pt++;
        }
        dp[0][i] = pt;
    }
    for(int i = 1; i < LOGN; i++) {
        fr(j, 1, n) {
            dp[i][j] = dp[i - 1][dp[i - 1][j]];
        }
    }
    fr(i, 1, q) {
        int l, r;
        cin >> l >> r;
        if(l > r) swap(l, r);
        int ans = 0;
        for(int i = LOGN - 1; i >= 0; i--) {
            if(dp[i][l] < r) {
                ans += (1 << i);
                l = dp[i][l];
            }
        }
        ans++;
        cout << ans << endl;
    }
}

signed main(){
    IO;
#ifdef LOCAL
    freopen("inp.txt","r", stdin);
#endif
    cout << setprecision(3) << fixed;
    //    srand(time(NULL));
    //    build();
    int t = 1;
//    cin >> t;
    fr(tt, 1, t){
//        cout << "Case #" << tt << ": ";
        solve();
    }
    return 0;
}


Measured memory_bytes: 15744
#include <bits/stdc++.h>
#define debug(x) cerr << "\n" \
                      << #x << " = " << x << ".\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define print(xx) cout << (xx) << endl
using namespace std;
#define int long long
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vint;
const int INF = ((1LL << 30) + (1LL << 29));
const ll MOD = 1000000007;

/* 
*/

//=================================================
int N;
vector<pii> A;
//=================================================
void input()
{
    cin>>N;
    A = vector<pii> (N);
    rep(i,N){
        int tmp;
        cin>>tmp;
        A[i] = make_pair(tmp,i);
    }
}

//=================================================
void solve()
{
    sort(A.rbegin(),A.rend());
    vector<int> b(N);
    pii a1 = make_pair(A[0].second,A[0].first);
    pii a2 = make_pair(A[1].second,A[1].first);
    rep(i,N){
        if (i == a1.first){
            cout<<a2.second<<endl;
        }
        else cout<<a1.second<<endl;
    }

}

//=================================================
signed main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 6272
import java.io.*;
        import java.math.BigDecimal;
        import java.math.BigInteger;
        import java.util.*;

public class Main {
    static Input in = new Input(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int N = in.nextInt();
        int[] x = new int[N];
        for (int i = 0; i < N - 1; i++)
            x[in.nextInt() - 1]++;
        for (int i = 0; i < N; i++)
            out.println(x[i]);
        out.flush();
    }

    static class Input {
        private BufferedReader br;
        private String[] buff;
        private int index = 0;

        Input(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }
        String nextLine() {
            try {
                return br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
        String next() {
            while (buff == null || index >= buff.length) {
                buff = nextLine().split(" ");
                index = 0;
            }
            return buff[index++];
        }
        byte nextByte() {
            return Byte.parseByte(next());
        }
        short nextShort() {
            return Short.parseShort(next());
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        float nextFloat() {
            return Float.parseFloat(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        BigInteger nextBigInteger() {
            return new BigInteger(next());
        }
        BigDecimal nextBigDecimal() {
            return new BigDecimal(next());
        }
    }
}

Measured memory_bytes: 63724
long five(long n){
  long ans=0; long bumbo=10;
  while(n>=bumbo) ans+=n/bumbo, bumbo=bumbo*5;
  return ans;
}

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  long n; cin>>n;
  if(n%2==1) cout<<0<<endl;
  else cout<<five(n)<<endl;
}


Measured memory_bytes: 384
n,l,*a=map(int,open(0).read().split())
ans=[]    
for i in range(1,n):
    if a[i]+a[i-1]<l:
        ans.append(i)
    else:
        for j in range(n-1,i-1,-1):
            ans.append(j)
        print("Possible")
        print(*ans,sep="\n")
        exit()
print("Impossible")      

Measured memory_bytes: 14092
s = int(input())
ans_list = {1:4,2:4,3:9,4:4,5:7,6:10,7:18,8:5,9:21,10:8,11:16,12:11,13:11,14:19,15:19,16:6,17:14,18:22,19:22,20:9,21:9,22:17,23:17,24:12,25:25,26:12,27:113,28:20,29:20,30:20,31:108,32:7,33:28,34:15,35:15,36:23,37:23,38:23,39:36,40:10,41:111,42:10,43:31,44:18,45:18,46:18,47:106,48:13,49:26,50:26,51:26,52:13,53:13,54:114,55:114,56:21,57:34,58:21,59:34,60:21,61:21,62:109,63:109,64:8,65:29,66:29,67:29,68:16,69:16,70:16,71:104,72:24,73:117,74:24,75:16,76:24,77:24,78:37,79:37,80:11,81:24,82:112,83:112,84:11,85:11,86:32,87:32,88:19,89:32,90:19,91:94,92:19,93:19,94:107,95:107,96:14,97:120,98:27,99:27,100:27}
#トンデモナイクソコード
print(ans_list[s])

Measured memory_bytes: 3188
fn select_type(c: &Vec<usize>, s: &Vec<Vec<isize>>, lastvals: &Vec<usize>, d: usize, used: &mut Vec<bool>) -> usize {
    let current_downval_data: Vec<usize> = lastvals.iter()
        .enumerate()
        .map(|pair| c[pair.0] * (d + 1 - pair.1))
        .collect()
    ;
    let ret = s[d].iter().zip(current_downval_data.iter())
        .map(|s_d| (*s_d.0 as isize - *s_d.1 as isize).abs())
        .enumerate()
        .filter(|&pair| !used[pair.0])
        .max_by_key(|x| x.1)
        .map_or(0, |pair| pair.0)
    ;
    used[ret] = true;
    ret + 1
}

fn downval(c: &Vec<usize>, lastvals: &Vec<usize>, d: usize) -> usize {
    lastvals.iter()
        .enumerate()
        .map(|pair| c[pair.0] * (d + 1 - pair.1))
        .sum()
}

fn main() {
    let mut d = String::new();
    std::io::stdin().read_line(&mut d).ok();
    let d: usize = d.trim().parse().unwrap();
    let mut c = String::new();
    std::io::stdin().read_line(&mut c).ok();
    let c: Vec<usize> = c.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let mut satisfied: Vec<Vec<isize>> = vec![vec![]; d];
    let mut lastvals: Vec<usize> = vec![0; 26];
    for i in 0..d {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).ok();
        let s: Vec<isize> = s.trim().split_whitespace().map(|t| t.parse().unwrap()).collect();
        satisfied[i] = s;
    }
    let mut result: isize = 0;
    let mut used: Vec<bool> = vec![false; 26];
    for i in 0..d {
        if i > 0 && i % 26 == 0 { used = vec![false; 26]; }
        let t = select_type(&c, &satisfied, &lastvals, i, &mut used);
        lastvals[t-1] = i+1;
        result += satisfied[i][t-1] as isize;
        result -= downval(&c, &lastvals, i) as isize;
        println!("{}", t);
        //println!("{} {}", t, result);
    }
}


Measured memory_bytes: 2292
#include<bits/stdc++.h>
using namespace std;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)


int main(){

    int N, W; cin >> N >> W;
    vector<int> v(N);
    vector<int> w(N);
    for(int i = 0; i < N; i++) cin >> v[i] >> w[i];

    int dp[110][10010] = {};
    for(int i = 0; i < N; i++){
        for(int j = 0; j <= W; j++){

            //とる
            if(j + w[i] <= W) chmax(dp[i + 1][j + w[i]], dp[i][j] + v[i]);

            //とらない
            chmax(dp[i + 1][j], dp[i][j]); 
        }
    }

    int ans = 0;
    for(int j = 0; j <= W; j++){
        chmax(ans, dp[N][j]);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 7416
#include <stdio.h>

int main(void){
  int s,rank,n;
  char c,suit[4]={'S','H','C','D'};
  int card[4][14];
  scanf("%d\n",&n);

  for(s=0;s<4;s++){
    for(rank=1; rank<14; rank++){
        card[s][rank] = 0;
    }
  }

  for(int i=0;i<n;i++){
    scanf("%c %d\n",&c,&rank);
    for(s=0;s<4;s++){
      if(suit[s]==c)
        card[s][rank]=1;
    }
  }
  
  for(s=0;s<4;s++){
    for(rank=1; rank<14; rank++){
      if(card[s][rank] == 0)
        printf("%c %d\n",suit[s],rank);
    }
  }


  return 0;
}
    


Measured memory_bytes: 2036