akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1 << 21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

// abc125c
ll gcd(ll x, ll y){
    if (x<y) swap(x, y);
    if (y==0) return x;
    return gcd(y, x%y);
}

int main(){
    int n;
    cin >> n;
    ll a[n];
    rep(i, n) cin >> a[i];
    ll l[n+1], r[n+1];
    l[0]=0;
    rep(i, n){
        if (i==0) continue;
        if (i==1){
            l[i] = a[i-1];
        }else{
            l[i] = gcd(a[i-1], l[i-1]);
        }
    }
    r[n-1] = 0;
    for(int i=n-1; i>=0; i--){
        if (i==n-1) continue;
        if (i==n-2){
            r[i] = a[i+1];
        }else{
            r[i] = gcd(a[i+1], r[i+1]);
        }
    }
    ll ans = 0;
    rep(i, n) chmax(ans, gcd(r[i], l[i]));
    cout << ans << endl;
    return 0;
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

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

	ll n;cin >> n;
	ll now = INF;
	ll ans = 0;
	REP(i, n){
		ll a;cin >> a;
		if(a <= now)ans++;
		now = min(now, a);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
lint inf=1E18L+1;
int main()
{
	int n;lint out=1,a;
	cin>>n;
	rep(i,n){
		cin>>a;
		if(out<1L) continue;
		if(inf/out+1<a) out=inf;else out*=a;
	}
	if(out>=inf) cout<<-1<<endl;
	else cout<<out<<endl;
}


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

using namespace std;

using ll = long long;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    cin >> n;
    ll now = -1,cnt=INF;
    for(i=0;i<n;i++){
        ll x,y;
        cin >> x >> y;
        if(x>now){
            now = x;
            cnt = y;
        }
    }
    cout << now + cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <climits>
#include <assert.h>
#include <cstring>
#include <set>

using namespace std;

typedef long long ll;

int main()
{
    ll x, k, d;
    cin >> x >> k >> d;

    if(x < 0)x = -x;

    if(x/d <= k)
    {
        k -= x/d;
        
        x = x-(x/d)*d;
        
        if(k%2 == 0)
        {
            cout << x;
            return 0;
        }
        else
        {
            cout << -(x-d);
            return 0;
        }
        
    }
    else
    {
        x = x-k*d;
        cout << x;
    }
    
}

Measured memory_bytes: 3588
r, c = map(int, input().split())

matrix = []

vsum = [0]*(c+1)

for i in range(r):
	row = list(map(int, input().split()))
	row.append(sum(row))
	matrix.append(row)
	for j in range(c+1):
		vsum[j] += row[j]

matrix.append(vsum)

for row in matrix:
	print(' '.join(list(map(str, row))))


Measured memory_bytes: 5700
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	//freopen("input.txt","r",stdin);
#endif

	int n;
	cin>>n;
	int count=0;
	for(int i=1;i<=n;i++)
	{
		int x;
		cin>>x;
		if(i%2!=0 && x%2!=0)
			count++;
	}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
 
#define mem(dp,a)       memset(dp,a,sizeof dp)
#define ninja           ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb(x)           push_back(x)
#define mp(x,y)         make_pair(x,y)
#define all(c)          c.begin(), c.end()
#define int             long long
#define ff              first
#define ss              second
#define nl              '\n'
#define inf             1e9+7
vector<int> adj[200005];
signed main()
{
	ninja
	
	int n; cin>>n;
	int x;
	for(int i=2;i<=n;i++){
			cin>>x;
			adj[x].pb(i);
	}
		for(int i=1;i<=n;i++){
			cout<<adj[i].size()<<nl;
		}
}



Measured memory_bytes: 14488
from itertools import combinations
N = int(input())
S = list(input())
L = S[:N]
R = S[:2*N][::-1]


digit = "0"+str(N)+"b"
LDic={}
for i in range(2**N):
    pattern = format(i,digit)
    red = []
    blue = []
    for i in range(N):
        if pattern[i] == "1":
            red.append(L[i])
        else:
            blue.append(L[i])
    red = "".join(red)
    blue = "".join(blue)
    key = ",".join([red,blue])
    if key in LDic:
        LDic[key] += 1
    else:
        LDic[key] = 1

RDic={}
for i in range(2**N):
    pattern = format(i,digit)
    red = []
    blue = []
    for i in range(N):
        if pattern[i] == "1":
            red.append(R[i])
        else:
            blue.append(R[i])
    red = "".join(red)
    blue = "".join(blue)
    key = ",".join([blue,red])
    if key in RDic:
        RDic[key] += 1
    else:
        RDic[key] = 1
ans = 0
for k,v in LDic.items():
    if k in RDic:
        ans += v*RDic[k]
print(ans)

Measured memory_bytes: 124832
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#define PI 3.14159265359
typedef long long ll;
const int MOD = 1e9+7;
const ll LLINF = 7e18;
using namespace std;

int h, w;
char grid[1001][1001];
vector<queue<pair<int, int> > > que(2);

bool is_range(int x, int y){
	if (1 <= x && x <= h && 1 <= y && y <= w) return true;
	return false;
}

void bfs(int x){
	int dirx[4] = {1, 0, -1, 0};
	int diry[4] = {0, 1, 0, -1};
	while(!que[x].empty()){
		auto f = que[x].front();
		que[x].pop();
		for (int i = 0; i < 4; i++){
			if (is_range(f.first + dirx[i], f.second + diry[i])){
				if (grid[f.first + dirx[i]][f.second + diry[i]] == '.'){
					grid[f.first + dirx[i]][f.second + diry[i]] = '#';
					que[(x+1)%2].push(make_pair(f.first + dirx[i], f.second + diry[i]));
				}
			}
		}
	}
	return;
}

int main(){
	cin >> h >> w;
	for (int i = 1; i <= h; i++){
		for (int j = 1; j <= w; j++){
			cin >> grid[i][j];
			if (grid[i][j] == '#'){
				que[0].push(make_pair(i, j));
			}
		}
	}

	int ans = 0;
	while(1){
		if (!que[0].empty()) bfs(0);
		else break;
		ans++;
		if (!que[1].empty()) bfs(1);
		else break;
		ans++;
	}

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

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

using namespace std;

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_2_B&lang=jp

struct Edge {
  int dst,weight;
};

int ChinesePostmanProblem(int V,int E,vector<int> s,vector<int> t,vector<int> d) {
  int mini = 0;
  vector<vector<Edge> > G(V);
  vector<vector<int> > wf(V,vector<int>(V,INT_MAX));
  for(int i=0;i<V;++i) wf[i][i] = 0;
  for(int i=0;i<E;++i) {
    G[s[i]].push_back((Edge){t[i],d[i]});
    G[t[i]].push_back((Edge){s[i],d[i]});
    wf[s[i]][t[i]] = wf[t[i]][s[i]] = min(wf[s[i]][t[i]],d[i]);
    mini += d[i];
  }
  for(int k=0;k<V;++k) for(int i=0;i<V;++i) for(int j=0;j<V;++j) if( wf[i][k] != INT_MAX && wf[k][j] != INT_MAX ) wf[i][j] = min(wf[i][j],wf[i][k]+wf[k][j]);
  vector<int> odd;
  for(int i=0;i<V;++i) if( (int)G[i].size() & 1 ) odd.push_back(i);
  int n = (int)odd.size();
  vector<int> dp((1<<n),INT_MAX);
  dp[0] = 0;
  for(int state=0;state<(1<<n);++state) {
    for(int sp=0;sp<n;++sp) if( !( (state>>sp) & 1 ) ) {
        for(int ep=0;ep<n;++ep) if( sp != ep && !( (state>>ep) & 1 ) )  {
            dp[state|(1<<sp)|(1<<ep)] = min(dp[state|(1<<sp)|(1<<ep)],
                                            dp[state]+wf[odd[sp]][odd[ep]]);
          }
      }
  }
  return mini + dp[(1<<n)-1];
}

int main() {
  int V,E;
  cin >> V >> E;
  vector<int> s(E),t(E),d(E);
  for(int i=0;i<E;++i) cin >> s[i] >> t[i] >> d[i];
  cout << ChinesePostmanProblem(V,E,s,t,d) << endl;
  return 0;
}

Measured memory_bytes: 1288
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int w = Integer.parseInt(sc.next());
		int h = Integer.parseInt(sc.next());
		int n = Integer.parseInt(sc.next());
		int[][] r = new int[w + 1][h + 1];
		for (int i = 0; i < n; i++) {
			int x = Integer.parseInt(sc.next());
			int y = Integer.parseInt(sc.next());
			int a = Integer.parseInt(sc.next());
			int sx = 0, sy = 0, fx = w + 1, fy = h + 1;
			if (a == 1)
				fx = x;
			else if (a == 2)
				sx = x + 1;
			else if (a == 3)
				fy = y;
			else
				sy = y + 1;
			for (int j = sx; j < fx; j++)
				for (int k = sy; k < fy; k++)
					r[j][k] = 1;
		}
		int minx = Integer.MAX_VALUE;
		int maxx = 0;
		int miny = Integer.MAX_VALUE;
		int maxy = 0;
		for (int i = 0; i <= w; i++)
			for (int j = 0; j <= h; j++) {
				if (r[i][j] != 1) {
					if (i < minx)
						minx = i;
					if (i > maxx)
						maxx = i;
					if (j < miny)
						miny = j;
					if (j > maxy)
						maxy = j;
				}
			}
		int ans = 0;
		if (minx != Integer.MAX_VALUE && miny != Integer.MAX_VALUE)
			ans = (maxx - minx) * (maxy - miny);
		System.out.println(ans);
	}
}

Measured memory_bytes: 22480
#include <bits/stdc++.h>
#define int int64_t
using namespace std;

signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin >> s;
	string before;
	int ans = 0, n =s.size();
	for (int i=0; i<n; ++i){
		string a;
		a += s[i];
		i++;
		while (i < n and before == a){
			a += s[i];
			i++;
		}
		if (before != a) ans++;
		i--;
		before = a;
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 1228
#include <stdio.h>
#include <stdlib.h>
int main(void){
    char n[1000000];
    int count=0;
    scanf("%s", &n);
    for(int i=0; n[i]!='\0'; i++){
        count+=n[i]-48;
    }
    if(count%9==0) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 1752
#include <bits/stdc++.h>
using namespace std;
#define incant() cin.tie(0), ios::sync_with_stdio(false)
#define int long long
#define uint unsigned long long
#define double long double
using str = string;
template <class T> using vec = vector<T>;
template <class T> using vvec = vec<vec<T>>;
template <class T> using que = queue<T>;
template <class T> using pque = priority_queue<T>;
template <class... T> using tup = tuple<T...>;
using vint = vec<int>;
using vvint = vvec<int>;
using vstr = vec<str>;
using pint = pair<int, int>;
using vp = vec<pint>;
using tll = tup<int, int, int>;
using vt = vec<tll>;
using mint = map<int, int>;
using dict = map<str, int>;
using qint = que<int>;
using qp = que<pint>;
using pqint = pque<int>;
using pqp = pque<pint>;
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fir first
#define sec second
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define sz(x) x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define ms(v, x) memset(v, x, sizeof(v))
#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 < (int)(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload3(__VA_ARGS__, revi, _rev,)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
#define out(x) cout << (x)
#define indent() cout << '\n'
#define print(x) out(x), indent()
#define debug(x) cerr << __LINE__ << ": " << #x << ": " << (x) << '\n'
#define YN(x) print((x) ? "YES" : "NO")
#define Yn(x) print((x) ? "Yes" : "No")
#define yn(x) print((x) ? "yes" : "no")
#define POS(x) print((x) ? "POSSIBLE" : "IMPOSSIBLE")
#define Pos(x) print((x) ? "Possible" : "Impossible")
#define pos(x) print((x) ? "possible" : "impossible")
const int INF = 1e16, MOD = 1e9 + 7, LIMIT = 100001;
const int dx4[] = {-1, 0, 1, 0}, dy4[] = {0, -1, 0, 1};
const int dx8[] = {-1, 0, 1, -1, 1, -1, 0, 1}, dy8[] = {-1, -1, -1, 0, 0, 1, 1, 1};
const double EPS = 1e-9;
int gcd(int a, int b){return b == 0 ? a : gcd(b, a % b);}
int lcm(int a, int b){return a / gcd(a, b) * b;}
int factorial(int a){return a < 2 ? 1 : factorial(a - 1) * a;}
int summation(int a){return a < 1 ? 0 : (a * a + a) / 2;}
int combination(int n, int r){int res = 1; rep(i, 1, r + 1) res *= n--, res /= i; return res;}
const str alphabet = "abcdefghijklmnopqrstuvwxyz";
int a, b, c, n, m, x, y, z, w, h, res = 0, cnt = 0, sum = 0, mx = -INF, mn = INF;
str s, t;
bool flag = true;

signed main(){
    incant();
    cin >> n;
    int dp[n + 1] = {}, v[n + 1] = {};
    rep(i, 1, n + 1){
        cin >> v[i];
        if(i > 2){
            dp[i] = min(dp[i - 1] + abs(v[i] - v[i - 1]), dp[i - 2] + abs(v[i] - v[i - 2]));
        }else if(i == 2){
            dp[2] = abs(v[2] - v[1]);
        }else{
            dp[i] = 0;
        }
    }
    print(dp[n]);
}

Measured memory_bytes: 1792
#import numpy as np
from copy import deepcopy
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

N = int(input())
#AB = [list(map(int, input().split())) for _ in range(N-1)]
edge = [[] for i in range(N)]
seen = [0]*N
colors = [0]*(N-1)
#for val in AB:
for i in range(N-1):
    x, y = list(map(int, input().split()))
    edge[x-1].append((i, y-1))
    edge[y-1].append((i, x-1))

lenedge = [len(val) for val in edge]
mledge = max(lenedge)
root = lenedge.index(mledge)
print(mledge)


que = deque()
que.append([(root, -1)])
while que[0]:
    nque = []
    cque = que.popleft()
    #print('cstack:', cstack)
    for tupl in cque:
        index, pcolor = tupl
        seen[index] = 1
        color = 1
        if (color == pcolor): color += 1
        for tupl2 in edge[index]:
            findex, edgei = tupl2
            if seen[edgei] == 0:
                nque.append((edgei, color))
                colors[findex] = color
                color += 1
                if (color == pcolor): color += 1
    que.append(nque)

#pri(color)

for color in colors:
    print(color)



Measured memory_bytes: 46344
//
// Created by inoue on 2019-10-27.
//

#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll;
typedef vector<vector<long long> > vvll;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i,n) _rep2((i),0,(n))
#define _rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define fi first
#define se second
#define mkp make_pair
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x)
#define debug(x)
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

ll mainmain(){
    int N;
    ll K;
    cin >> N >> K;
    vint A(N);
    vint F(N);
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> F[i];

    sort(ALL(A));
    reverse(ALL(A));
    sort(ALL(F));

    {
        ll sum = 0;
        rep(i, N) sum += A[i];
        if (sum <= K) {
            return 0;
        }
    }

    ll l = 0;
    ll h = INFL;

    while(h-l>1) {
        ll mid = (h+l)/2;

        ll tmp = 0;
        rep(i, N) {
            ll t = mid / F[i];
            assert(t * F[i] <= mid);
            tmp += max(0LL, A[i]-t);
        }

        if (tmp <= K) {
            h = mid;
        }
        else {
            l = mid;
        }
    }

    return h;
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    cout << mainmain() << endl;
}



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

bool isPrime(int n)
{
        if( n==1 ){ return false; }
        if( n==2 ){ return true;  }
        if(!(n%2)){ return false; }


        int m;
        bool flag = true; 
        m = sqrt(n);
        if(!(m%2)){ m--; }
        while( m>1 ){
                if( !(n%m) ){ flag=false; break; }
                m -= 2;
        }
        return flag;
}

int main()
{
        int n, num, prime;
        cin >> n;
        prime = 0;

        for(int i=0; i<n; i++){
                cin >> num;
                if(isPrime(num) == true ) prime++;
        }
        cout << prime << endl;

        return 0;
}

                        

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

#define ll long long
#define vi vector<int>
#define pi pair<int, int>
  
using namespace std;                           

string s;
 
int main (){
	cin >> s;
	sort(s.begin(),s.end());
	for(int i = 0; i < s.size(); i++){
		if(s[i] == s[i + 1]){
			cout << "no";
			return 0;
		}
	}
	cout << "yes";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end() 

int const N = 200001;
int n, v[N], sg[4 * N], l, r;

void bld(int u, int s, int e){
     if(s == e){sg[u] = v[s]; return;}
     bld(u*2, s, s+e>>1);
     bld(u*2+1, (s+e>>1)+1, e);
     sg[u] = __gcd(sg[u*2], sg[u*2+1]);
}

int gt(int u, int s, int e){
    if(s > r || e < l)return 0;
    if(s >= l && e <= r)return sg[u];
    return __gcd(gt(u*2, s, s+e>>1), gt(u*2+1, (s+e>>1)+1, e));
}


int main(){
    scanf("%d", &n);
    for(int i = 0; i<n; ++i)scanf("%d", v+i);
    bld(1, 0, n-1);
    l = 0, r = n-1;
    int an = gt(1, 0, n-1);
    for(int i = 1; i<n-1; ++i){
       l = 0, r = i-1;
       int lg = gt(1, 0, n-1);
       l = i+1, r = n-1;
       int rg = gt(1, 0, n-1);
       an = max(an, __gcd(lg, rg));
    }
    l = 1, r = n-1;
    an = max(an, gt(1, 0, n-1));
    l = 0, r = n-2; 
    an = max(an, gt(1, 0, n-1));
    printf("%d\n", an);
}

Measured memory_bytes: 1664
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define U(v) cerr << #v << ": " << (v) << endl

int main() {
    string s;
    cin >> s;
    for (int i = 0; i < (int)s.size() - 8; ++i)
        cout << s[i];
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
L = []
for i in range(N):
    S, P = input().split()
    L.append((S, int(P), i + 1))

L.sort(key=lambda x: x[1], reverse=True)
L.sort(key=lambda x: x[0])

for l in L:
    print(l[2])


Measured memory_bytes: 3060
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <cmath>         // sqrt
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <bits/stdc++.h> // isupper, islower, isdigit, toupper, tolower
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, n) for (int i = (a); i < (n); i++)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pl;
typedef pair<int, int> P;
typedef tuple<ll, ll, string> Tlls;

// Greatest Common Divisor (最大公約数)
ll gcd(ll a, ll b)
{
  // Eucledean algorithm
  while (a)
  {
    if (a < b)
    {
      std::swap(a, b);
    }
    a %= b;
  }
  return b;
}

// Least Common Multiple 最小公倍数
ll lcm(ll a, ll b)
{
  return a / gcd(a, b) * b;
}

// key: value of prime factor素因数分解
// value: number of prime factor
map<ll, ll> prime_factorization(ll n)
{
  map<ll, ll> prime_factors;
  for (ll i = 2; i * i <= n; i++)
  {
    while (n % i == 0)
    {
      prime_factors[i]++;
      n /= i;
    }
  }
  if (n != 1)
    prime_factors[n] = 1;
  return prime_factors;
}

// 約数リスト約数の列挙
vector<ll> get_divisors(const ll n)
{
  vector<ll> divs;
  for (ll i = 1; i < (ll)sqrt((ld)n) + 1; i++)
  {
    if (n % i == 0)
    {
      divs.push_back(i);
      if (i != n / i)
      {
        divs.push_back(n / i);
      }
    }
  }

  // 必要に応じてソート
  // sort(divs.begin(), divs.end());

  return divs;
}

int main()
{
  ll H1, M1, H2, M2, K, time1, time2, time;
  cin >> H1 >> M1 >> H2 >> M2 >> K;
  ll ans = 0;
  time1 = H1 * 60 + M1;
  time2 = H2 * 60 + M2;
  time = time2 - time1;

  cout << time - K << endl;
  // ans = time / K;
  // if (ans * K == time)
  // {
  //   cout << ans * K - K << endl;
  // }
  // else if (ans * K - K > time)
  // {
  //   cout << ans * K - 2 * K << endl;
  // }
  // else
  // {
  //   cout << ans * K - K << endl;
  // }
  return 0;
}


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

int head[26], tail[26], visit[26];
int graph[26][26];

int sameNumber(void)
{
    int i;
    for (i = 0; i < 26; i++){
        if (head[i] != tail[i]){
            return (0);
        }
    }
    return (1);
}

void travelGraph(int node)
{
    int i;
    for (i = 0; i < 26; i++){
        if (graph[node][i] == 1){
            graph[node][i] = 0;
            visit[i] = 1;
            travelGraph(i);
        }
    }
}

int graphNumber(void)
{
    int i;
    int num;
    
    num = 0;
    for (i = 0; i < 26; i++){
        if (head[i] == 0 && tail[i] == 0){
            continue;
        }
        if (visit[i] == 0){
            num++;
            travelGraph(i);
        }
    }
    
    return (num);
}

int main(void)
{
    int i;
    int n;
    char str[256];
    
    while (1){
        scanf("%d", &n);
        
        if (n == 0){
            break;
        }
        
        memset(graph, 0, sizeof(graph));
        memset(tail, 0, sizeof(tail));
        memset(head, 0, sizeof(head));
        memset(visit, 0, sizeof(visit));
        
        for (i = 0; i < n; i++){
            scanf("%s", str);
            
            head[str[0] - 'a']++;
            tail[str[strlen(str) - 1] - 'a']++;
            graph[str[0] - 'a'][str[strlen(str) - 1] - 'a'] = 1;
            graph[str[strlen(str) - 1] - 'a'][str[0] - 'a'] = 1;
        }
        
        if (sameNumber() && graphNumber() == 1){
            printf("OK\n");
        }
        else {
            printf("NG\n");
        }
    }
    
    return (0);
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N;

signed main(){
	cin>>N;
	int ans=0;
	for(int i=1;i<N;i++){
		ans+=N/i;
		if(N%i==0){
			ans--;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int N;
    cin>>N;
    int A[N];
    int sum=0;
    rep(i,N) {
        cin>>A[i];
        sum+=A[i];
    }
    int x=0;
    for(int i=0;i<N-1;i+=2){
        x+=A[i]*2;
    }
    int ans[N];
    ans[N-1]=sum-x;
    ans[0]=2*A[N-1]-ans[N-1];
    rep(i,N-1){
        ans[i+1]=2*A[i]-ans[i];
    }
    rep(i,N){
        cout << ans[i] << " ";
    }
    cout << endl;
                                                                     



}


Measured memory_bytes: 2944
#include<iostream>
using namespace std;
int main(){
  int n;
  int i,j;
  while(1){
    cin >> n;
    if(n==0)break;
    int data[11][11]={0};
    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
	cin >> data[i][j];
	data[i][n]+=data[i][j];
	data[n][j]+=data[i][j];
	data[n][n]+=data[i][j];
      }
     }
    for(i=0;i<=n;i++){
      for(j=0;j<=n;j++){
	cout.width(5);
	//	cout.fill(' ');
	cout << data[i][j];
      }
      cout << endl;
    }
  }
}

Measured memory_bytes: 1172
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N;
string S;


signed main(){
	cin>>N>>S;
	string T=S;
	sort(T.begin(),T.end());
	int cnt=0;
	REP(i,N){
		if(T[i]=='W')break;
		if(S[i]!=T[i]){
			cnt++;
		}
	}
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 3856
L, R = map(int, input().split())
a = 2020

if(R-L > 2019):
    R = L+2019
for i in range(L,R+1):
    for j in range(i+1,R+1):
        ans = i*j%2019
        if(a > ans):
            a = ans
print(a)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int n,m;
int ans=0x3f3f3f3f;
int a[100005];
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++) cin>>a[i];
	sort(a+1,a+1+n);
	for(int i=m;i<=n;i++) ans=min(ans,a[i]-a[i-m+1]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

class cShell
{
	int m_n;
	int cnt;
	vector<int> vA;
	vector<int> vg;

	void insertionSort(int g);

public:
	cShell(int n, vector<int> & v)
	{
		vA = v;
		m_n = n;
		cnt = 0;
	}
	
	void shellSort();

	int getm()
	{
		return vg.size();
	}

	string getGapToStr();

	vector<int> getData()
	{
		return vA;
	}

	int getCnt()
	{
		return cnt;
	}
};

void cShell::insertionSort(int g)
{
	for (int i = g; i < m_n; ++i)
	{
		int v = vA[i];
		int j = i - g;
		while (j >= 0 && vA[j] > v)
		{
			vA[j + g] = vA[j];
			j = j - g;
			cnt++;
		}
		vA[j + g] = v;
	}
}

void cShell::shellSort()
{
	int cnt = 0;
	int m = vA.size();
	if (m / 2 > 0)
	{
		while (m /= 2)
		{
			vg.push_back(m);
		}
	}
	else
	{
		vg.push_back(1);
	}
	for (int i = 0; i < vg.size(); ++i)
	{
		insertionSort(vg[i]);
	}
}

string cShell::getGapToStr()
{
	ostringstream oss;
	for (int i = 0; i < vg.size() - 1; ++i)
	{
		oss << vg[i] << " ";
	}
	oss << vg[vg.size() - 1];
	return oss.str();
}

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

	vector<int> va;
	for (int i = 0; i < n; ++i) {
		int t;
		cin >> t;
		va.push_back(t);
	}

	cShell cs(n, va);
	cs.shellSort();

	cout << cs.getm() << endl;
	cout << cs.getGapToStr() << endl;
	cout << cs.getCnt() << endl;
	va = cs.getData();
	for (int i = 0; i < va.size(); ++i)
	{
		cout << va[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 13016
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 
const int mod=1e9+7;
 
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};
 
mint c[4005][4005];
void init() {
  c[0][0] = 1;
  for (int i = 0; i <= 4000; i++) {
    for (int j = 0; j <= i; j++) {
      c[i+1][j] += c[i][j];
      c[i+1][j+1] += c[i][j];
    }
  }
}
mint comb(int n, int k) {
  return c[n][k];
}
 
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
 
    return true;
}
 
map<ll, ll> primeFact(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n]++;
  return res;
}
 
void printv(vi& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
void printv(vll& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}
 
int main()
{
  //init(); // mint初期化
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  int a,b,c;cin>>a>>b>>c;
  int ans;
  if(a==b)ans=c;
  else if(a==c)ans=b;
  else ans=a;
  cout(ans);
  
  return 0;
}

Measured memory_bytes: 125696
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
using namespace std;
const long long MAX = 10000000;
const long long MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (long long i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        //そのまま計算すると負の値になるのでMODを足す
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(long long n, long long k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main() {
    COMinit();
    long long a, b;
    cin >> a >> b;
    map<long long, long long> v;
    long long tmpb = b;
    for(long long i=2;i*i<=b;i++) {
        while(tmpb % i == 0) {
            tmpb /= i;
            v[i] += 1;
        }
    }
    if(tmpb!=1) v[tmpb] += 1;
    long long ans = 1;
    for(auto m:v) {
        //cout << m.first << " " << m.second << endl;
        ans = (ans * COM(m.second+a-1, a-1))%MOD;
    }
    cout << ans << endl;
} 
/*
2 2 3


a1b2 b1b2 c1c2
a1+b1+b2 = 2
a2+b2+c2 = 1
*/

Measured memory_bytes: 234752
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define LINT long long

int main(){
  int N;
  cin >> N;
  int a[N];
  int cols[9]={};
  int b;
  REP(i, N){
    cin >> a[i];
    b = a[i]/400;
    if(b>8) b=8;
    ++cols[b];
  }
  int cols_min=0;
  REP(i, 8){
    if(cols[i]) ++cols_min;
  }
  int cols_max=cols_min + cols[8];
  if(!cols_min) ++cols_min;
  cout << cols_min << " " << cols_max << endl;


  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
using ll = long long;

string s, t;

vector<vector<int>> idx(1 << 8);

int dist(int x, int y) {
    if(y == x) return s.size();
    if(x < y) return y - x;
    else return s.size() - (x - y);
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> s >> t;
    for(int i = 0; i < s.size(); ++i) {
        idx[s[i]].push_back(i);
    }
    ll ans = 0;
    int j = -1;
    for(char c : t) {
        if(idx[c].size() == 0) {
            cout << -1 << '\n';
            return 0;
        }
        auto it = upper_bound(idx[c].begin(), idx[c].end(), j);
        if(it == idx[c].end()) {
            it = idx[c].begin();
        }
        ans += dist(j, *it);
        j = *it;
    }
    cout << ans << '\n';
}


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

using namespace std;

int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    vector<int>b(n);
    for(int i=0;i<n;i++){
        cin>>a.at(i);
        b.at(i)=a.at(i);
    }

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

    int c=0;
    for(int i=0;i<n;i++){
        if(b.at(i)!=a.at(i)){
            c++;
        }
    }
    if(c==0){
        cout<<"YES"<<endl;
    }else if(c==2){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}



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

using ll=long long;
const ll INF=1LL<<60;
const ll MOD=1e9+7;

struct Point{
    int x;
    int y;
};


int main(){
    while(1){
        int m; cin >> m;
        if(m == 0) break;
        vector<Point> point1(m);
        for(int i=0; i<m; i++){
            cin >> point1[i].x >> point1[i].y;  
        }
        int n; cin >> n;
        vector<Point> point2(n);
        for(int i=0; i<n; i++){
            cin >> point2[i].x >> point2[i].y;
        }
        Point res;
        for(int i=0; i<n; i++){
            int dx=point2[i].x-point1[0].x;
            int dy=point2[i].y-point1[0].y;
            bool ok;
            for(int j=1; j<m; j++){
                ok=false;
                int nx=point1[j].x+dx;
                int ny=point1[j].y+dy;
                for(int k=0; k<n; k++){
                    if(point2[k].x == nx && point2[k].y == ny) ok=true;
                }
                if(!ok) break;
            }
            if(ok){
                res.x=dx;
                res.y=dy;
            }
        }
        cout << res.x << " " << res.y << endl;
    }
    return 0;
}


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m,sum=0,i,j,dum;
    cin>>n>>m;
    priority_queue<ll>q;
    for(i=0;i<n;i++){
        cin>>j;
        q.push(j);
    }
    i=0;
    while(i<m){
        dum=q.top();
        dum/=2;
        
        q.pop();
        q.push(dum);
        i++;
        
    }
    while (!q.empty()) 
    { 
        sum+=q.top(); 
        q.pop(); 
    } 
    
    cout<<sum;
 
  return 0;
    
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
#define MOD7 1000000007
#define MOD9 1e9 + 9
#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define MEM(a, b) memset(a, (b), sizeof(a))
typedef long long ll;
typedef long double ld;
typedef string str;
typedef double d;
typedef unsigned u;
typedef unsigned long long ull;

const long long BIGINF = 2e18 + 7;
const int INF = 2e9 + 7;


int main () {
	/*#ifndef ONLINE_JUDGE
		freopen("inputf.txt", "r", stdin);
		freopen("outputf.txt", "w", stdout);
	#endif*/
	long long n;
	SCLLD(n);
	long long k = 1;
	while (k <= n) {
		k *= 2;
	}
	printf("%lld", k - 1);

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr
#define INT_MAX_HALF (INT_MAX / 2)

typedef long long ll;

using namespace std;
//using namespace boost::multiprec

int main(){

    int n;
    cin >> n;

    vector<int> v, v2;

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

        v.pback(tmp);
        v2.pback(tmp);
    }

    sort(ALL(v2));

    int first = v2[n - 1];
    int second = v2[n - 2];

    rep(i,n){
        if(v[i] == first){
            cout << second << endl;
        }else{
            cout << first << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3436
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))+[0]
ans=c=0
for i in range(N+1):
    a=A[i]
    b=B[i]
    ans+=min(a,c)
    a=max(a-c,0)
    ans+=min(a,b)
    c=max(b-a,0)
print(ans)

Measured memory_bytes: 18624
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll ;
typedef double db;
const double pi = 3.141592654;
#define pb         push_back
#define forab(i,a,b)       for(int i=(a);i<=(b);i++)
#define CIN	ios_base::sync_with_stdio(0); cin.tie(0)
#define pcase(z,x)     printf("Case %ld: %lld\n",z,x)
#define nw				"\n"
int main(void)
{
	CIN;
	ll tc,l,k,sum=0,x=0,y,z=0,m=1,n=0,ans=0,cnt=0;
	string s;
	cin>>s;
	l=s.size();
	for(ll i=0;i<l;i++){
		if((i%2&&s[i]=='1')||(i%2==0&& s[i]=='0'))cnt++;
	}
	cout<<min(cnt,(int)s.size()-cnt);
}

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

#define fi first
#define se second
#define pb push_back
#define lson o<<1
#define rson o<<1|1
#define CLR(A, X) memset(A, X, sizeof(A))
#define bitcount(X) __builtin_popcountll(X)
typedef long long LL;
typedef pair<int, int> PII;
const double eps = 1e-10;
const LL MOD = 1e9+7;
const auto INF = 0x3f3f3f3f;
int dcmp(double x) { if(fabs(x) < eps) return 0; return x<0?-1:1; }

const int MAXN = 55;

char s[MAXN];

int main() {
    scanf("%s", s);
    int len = strlen(s);
    for(int i = 0; i < len-8; i++) {
        printf("%c", s[i]);
    }
    puts("");
    return 0;
}



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

using namespace std;
#define int long long
int MOD = 1000000007;

signed main(){
    int H,W;
    cin >> H >> W;
    
    string C;
    for(int i=0;i<H;i++){
        cin >> C;
        
        cout << C << endl;
        cout << C << endl;
        
    }
    return 0;
}


Measured memory_bytes: 256
using System;

namespace ITP1_2_D
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int W = int.Parse(str[0]);
            int H = int.Parse(str[1]);
            int x = int.Parse(str[2]);
            int y = int.Parse(str[3]);
            int r = int.Parse(str[4]);

            Console.WriteLine((x - r >= 0 && x + r <= W && y - r >= 0 && y + r <= H) ? "Yes" : "No");
        }
    }
}

Measured memory_bytes: 8892
/* Author : Aaryan Srivastava ^__^ */ 
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define pb push_back
#define popb pop_back
#define mt make_tuple 
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second   
#define beg begin
#define rep(i,n) for(int (i) = 0 ; i < (n) ; i++)
#define repA(i,x,y) for(int i = (x) ; i <= (y) ; i++)
#define repD(i,x,y) for(int i = (x) ; i >= (y) ; i--)
#define all(c) (c).begin(),(c).end()
#define fill(a,val) memset(a,val,sizeof(a))
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define trav(x , a) for(auto &x : a)
#define sz(a) ((int)a.size())
typedef long long ll ; 

#define int ll

using namespace std;

const int N = 3e5 +5 ;
const int mod = 1e9 + 7 ;
const ll inf = 1e18 ;
const int SZ = 101 ;
const double eps = 1e-9 ;
using namespace __gnu_pbds;
using ordered_set =  tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ;

typedef vector<int> vi;
typedef pair<int, int> pii; 
typedef pair<int , pii> piii ; 
typedef unsigned long long ull ;


void solve()
{
    int a , b , c;
    cin >> a >> b >> c; 
    if(a + b > c){
        cout << "No\n";
    }else if(4LL * a * b < (c - (a + b))){
        cout << "Yes\n" ;
    }else{
        cout << (4LL * a * b < (c - (a + b)) * (c - (a + b)) ? "Yes" : "No");    
    }  
} 

     
int32_t main(int32_t argc, char *argv[])
{
    ios::sync_with_stdio(0);    
    cin.tie(0); cout.tie(0);
    int TC = 1, t = 0;
    //cin >> TC ;
    while(t++ < TC)
    {
        //cout << "Case #" << t << ": " ;
        solve();
        cout << "\n" ;
    }
    return 0;
}

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

int main() {
    string s;
    cin >> s;
    string ans = "No";
    if (s.find('7') != string::npos) ans = "Yes";
    cout << ans << endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
#define pb push_back
#define FOR(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define F first
#define S second
const int NUM = 2e5 + 5;
signed main(){
    int t = 1; //cin >> t;
    while(t--){
        int n; cin >> n;
        vector<pair<int,int>> p;
        for(int i = 0; i < n; i++)
        {
            int x,y ; cin  >>x >> y;
            p.push_back({x,y});
        }
        int ans = 0;
        for(int i = 0; i <= n-3; i++)
        {
            if(p[i].first == p[i].second and p[i+1].first == p[i+1].second and p[i+2].second == p[i+2].first)
            {
                cout << "Yes";
                return 0;
            }
        }
        cout << "No";
    }    
}


Measured memory_bytes: 3636
#include <iostream>
#include <stdio.h>
#include <cmath>
 
#define rep(i,n) for(int i = 0; i < n; i++)
 
typedef long long ll;
 
using namespace std;
 
const ll INF = ll(1e18)+1;
const double PI=3.14159265358979323846;
 
int main(){
  int a,p;
  cin >> a >> p;
  cout << (a*3 + p)/2 << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
  int N;
  cin >> N;
  int n = N;
  int fx = 0;
  while (n > 0) {
    fx += n%10;
    n /= 10;
  }
  if (N%fx==0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
<?php
// 入力
$s = trim(fgets(STDIN));

// ブロックごとの配列作成
$n = strlen($s);
$s_tmp = [['val' => 'R', 'cnt' => 0]];
for ($i = 0; $i < $n; ++$i) {
    $n_tmp = count($s_tmp);
    if ($s[$i] === $s_tmp[$n_tmp - 1]['val']) {
        ++$s_tmp[$n_tmp - 1]['cnt'];
    } else {
        $s_tmp[] = ['val' => $s[$i], 'cnt' => 1];
    }
}

// 答え出力用配列に0格納
$result = array_fill(0, $n, 0);

// ブロックごとに最終位置に加算
$top = 0;
foreach ($s_tmp as $val) {
    if ($val['val'] === 'R') {
        $target = $top + $val['cnt'] - 1;
        $result[$target] += ceil($val['cnt'] / 2);
        $result[$target + 1] += floor($val['cnt'] / 2);
    } else {
        $target = $top - 1;
        $result[$target] += floor($val['cnt'] / 2);
        $result[$target + 1] += ceil($val['cnt'] / 2);
    }
    $top += $val['cnt'];
}

// 出力
echo implode(' ', $result).PHP_EOL;

Measured memory_bytes: 78836
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <time.h>
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FFOR(i,a,b) for(int i=(a);i<=(b);i++)
#define REP(i,b) FOR(i,0,b)
#define RREP(i,b) FFOR(i,1,b)
#define PB push_back
#define F first
#define S second
#define BE(c) c.begin(),c.end()
using namespace std;
typedef long long LL;
typedef int ut;
typedef long double ld;
typedef pair<ut,ut> pr;
typedef vector<pr> Vpr;
typedef vector<ut> VI;
typedef pair<ut,pr> ppr;
typedef priority_queue<pr,Vpr, greater<pr> > PQ;
const int SIZE=1e+5 + 1;
const ut INF=1<<30;
const ld eps=1e-6;
const LL mod=1e+9 + 7;

int N, M;
vector<ppr> G;

const int MAX_N = 1000;

int par[MAX_N + 1], r[MAX_N + 1];

void init(int n){
	for(int i = 0; i < n; ++i){
		par[i] = i;
		r[i] = 0;
	}	
}

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

void unite(int x, int y){
	x = find(x);
	y = find(y);
	if(x == y)
		return;
		
	if(r[x] < r[y]){
		par[x] = y;
	}
	else{
		par[y] = x;
		if(r[x] == r[y])
			r[x]++;
	}
}

bool same(int x, int y){
	return find(x) == find(y);
}

int main() {
	while(cin >> N >> M && N){
		G.clear();
		REP(i,M){
			int a, b, c;
			scanf("%d%d%d", &a, &b, &c);
			G.PB(ppr(c, pr(a, b)));
		}
		init(N+1);
		sort(BE(G));
		int ans = 0;
		REP(i,G.size()){
			ppr e = G[i];
			if(!same(e.S.F, e.S.S)){
				unite(e.S.F, e.S.S);
				ans += e.F;
			}
		}
		cout << ans << endl;
	}
  return 0;
}

Measured memory_bytes: 1260