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

#define int long long int
#define main signed main()
#define bye return 0
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define each(p, v) for (auto p = (v).begin(); p != (v).end(); p++)
#define all(v) (v).begin(), (v).end()
#define prec(n) fixed << setprecision(n)
#define dump(x) cerr << "(L" << __LINE__ << ") " << #x << " = " << (x) << endl
#define clr(x, a) memset(x, a, sizeof(x))

#define sum(v) accumulate(all(v), 0)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define odd(n) ((n) % 2)
#define even(n) (!odd(n))

#define INF 1000000000
#define MOD 1000000007

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define vi vector<int>
#define vb vector<bool>
#define vc vector<char>

using namespace std;

main {
  bool a[] ={true,false,false};
  char p,x,q;
  while(cin>>p>>x>>q) {
    swap(a[p-'A'],a[q-'A']);
  }
  cout<<(a[0]?'A':a[1]?'B':'C')<<endl;
  bye;
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int LL;
typedef LL ll;
typedef string str;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef stringstream strs;
 
#define X first
#define Y second
#define PB push_back
#define For(i,a,b) for (int i=a;i<b;i++)
#define Ford(i,a,b) for (int i=a;i>=b;i--)
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define SZ(a) ((ll)a.size())
#define ER(a) cout << #a << ' ' << a << endl
#define LB(a,n,x) (lower_bound(a,(a)+(n),x)-(a))
#define RET(x) { cout << x; exit(0); } 
const ll M=2e5+5,LG=19,SM=4000+5,inf=1e18+1;
ll mod=1e9+7;

ll par[M];
vll ch[M];
ll n,k,res;

ll dfs(ll x)
{
    ll h=1;
    for (ll y:ch[x])
    {
        if (y==par[x]) continue;
        smax(h,dfs(y)+1);       
    }
    if (h==k && par[x]!=0)
    {
        res++;
        return 0;
    }
    return h;
}

int main()
{
	ios::sync_with_stdio(0);
    cin >> n >> k;
    cin >> par[0];
    res=par[0]!=1;
    par[0]=0;
    For(i,1,n)
    {
        cin >> par[i];
        par[i]--;
        ch[par[i]].PB(i);
    }
    dfs(0); 
    RET(res);     
}

Measured memory_bytes: 14208
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <string>
#include <set>

using namespace std;

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

  set<string> S;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    S.insert(s);
  }

  cout << S.size() << endl;
  return 0;
}


Measured memory_bytes: 15724
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <set>
#include <complex>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59

int main()
{
    //std::ios::sync_with_stdio(false);
    //std::cin.tie(0);
    cout << fixed << setprecision(7);

    int x, h;
    while (cin >> x >> h)
    {
        if (x == 0 && h == 0)
            break;
        long double t = (double)x * x / 2.0 + (double)h * h - (double)x * x / 4.0;

        double lb = 0.0, ub = 100000.0;
        for (int i = 0; i < 100; ++i)
        {
            double mid = (lb + ub) / 2;
            if (t > mid * mid)
            {
                lb = mid;
            }
            else if (t < mid * mid)
            {
                ub = mid;
            }
            else
            {
                lb = mid;
                break;
            }
        }
        cout << (double)2.0 * x * (double)lb + x * x
             << endl;
    }
    return 0;
}


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

int main(void) {
	int n, o = 0, cur = 0, tmp = 0, t = 0;
	cin >> n;
	vector<int> h(n);
	for(int i = 0; i < h.size(); i++) {
		cin >> h.at(i);
	}
	for(int i = 0; i < h.size(); i++) {
		cur = h.at(i);
		if(i == 0) {
			tmp = cur;
		}
		else if(tmp >= cur) {
			o += 1;
		}
		else if(tmp < cur) {
			o = 0;
		}
		tmp = cur;
		if(o > t) {
			t = o;
		}
	}
	cout << t << endl;
	return 0;
}

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

void solve()
{
    ll n;
    cin >> n;

    string res = "";
    while(n)
    {
        int t = n%26;
        n /= 26;
        if(t==0)
        {
            n--;
            res += 'z';
        }
        else
        {
            res += 'a' + t-1;
        }
    }
    reverse(res.begin(), res.end());
    cout << res << endl;
}


int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll t;
    solve();
    return 0;
}


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

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N; cin >> N;
	int MW; cin >> MW;
	int W0;
	vector<vector<int>> dp(N+1, vector<int>(3*N+1));
	for (int i = 0; i < N; i++) {
		int w, v; cin >> w >> v;
		if (i == 0) W0 = w;
		assert(W0 <= w && w <= W0 + 3);
		w -= W0;
		for (int c = i; c >= 0; c--) {
			for (int t = 0; t <= 3 * i; t++) {
				dp[c+1][t+w] = max(dp[c+1][t+w], dp[c][t] + v);
			}
		}
	}
	int ans = 0;
	for (int c = 0; c <= N; c++) {
		for (int t = 0; t <= 3 * N; t++) {
			if (1ll * W0 * c + t <= MW) {
				ans = max(ans, dp[c][t]);
			}
		}
	}
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 384
k = 0
def fizz(n,k):
    for ele in range(n+1):
        if ele%15==0:
            continue
        elif ele%3 == 0:
            continue
        elif ele%5 == 0:
            continue
        else:
            k += ele
    return k
n = int(input())
print(fizz(n,0))



Measured memory_bytes: 72964
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define m_k make_pair
#define int long long
using namespace std;
int n,k;
signed main()
{
	scanf("%lld%lld",&n,&k);
	int a=n/k;
	printf("%lld\n",min(n-a*k,(a+1)*k-n));
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<utility>
#include<tuple>
#include<string>
#include<vector>
#include<numeric>
#include<algorithm>
#include<queue>
#include<deque>
#include<bitset>
#include<cmath>
#include<map>
#include<iomanip>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
#define rep(i, a, b) for(int i = a; i < b; i++)

int main() {
	
	double x, y;
	cin >> x >> y;

	int a = y;
	if (a % 2 != 0) {
		cout << "No" << endl;
		return 0;
	}

	if(y / 4 > x) {
		cout << "No" << endl;
		return 0;
	}

	if(y / 2 < x) {
		cout << "No" << endl;
		return 0;
	}

	if (x == 1) {
		if(y != 2 && y != 4) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
	
	return 0;
}

Measured memory_bytes: 3716
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define MAX_V 400010
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
template<typename A, size_t NNN, typename T>
void Fill(A (&array)[NNN], const T &val){
    fill( (T*)array, (T*)(array+NNN), val );
}
#define INF 1e9+7
#define LLINF 1e18+7
ll MOD=1e9+7;
#define N 300000
ll n,m;
ll dp[N][200];
ll dp2[N][200];
int main(){
    string s;
    cin>>s;
    int d=in();
    rep(i,10){
        int t=s[0]-'0';
        if(i<t)dp[0][i%d]++;
    }
    int now=(s[0]-'0');
    rep2(i,1,s.size()-1){
        rep(j,d){
            rep(k,10){
                dp[i][(j+k)%d]=(dp[i][(j+k)%d]+dp[i-1][j])%MOD;
            }
        }
        int t=(s[i]-'0');
        rep(j,10){
            if(j<t){
                dp[i][(now+j)%d]=(dp[i][(now+j)%d]+1)%MOD;
            }
        }
        now=(now+t)%d;
    }
    now%=d;
    if(now==0)dp[s.size()-1][0]++;
    cout<<(dp[s.size()-1][0]+MOD-1)%MOD;
    return 0;
}

Measured memory_bytes: 18688
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
// #define ll int
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[8] ={1,0,-1,0,1,-1,1,-1};
ll dy[8] ={0,1,0,-1,1,-1,-1,1};
 
template<class T> 
inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> 
inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};


 
void solve(){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<max(a*b,c*d)<<endl;
}
 
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // Timer TM;
     
    ll Q=1;
    // cin>>Q;
    rep(_,Q){
 
        solve();
 
    }
   
 
 
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#define LEN 10

using namespace std;

int main(void) {
	int N;
	cin >> N;
	long long res = 0;
	vector<char> str(LEN);
	map< vector<char>,int > memo;
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < LEN; ++j) {
			cin >> str[j];
		}
		sort(str.begin(),str.end());
		res += memo[str];
		++memo[str];
	}

	cout << res << endl;
	return 0;
}


Measured memory_bytes: 11136
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cctype>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(c,i) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

string solve(double x)
{
	if(x<=48.00)
		return "light fly";
	if(x<=51)
		return "fly";
	if(x<=54)
		return "bantam";
	if(x<=57)
		return "feather";
	if(x<=60)
		return "light";
	if(x<=64)
		return "light welter";
	if(x<=69)
		return "welter";
	if(x<=75)
		return "light middle";
	if(x<=81)
		return "middle";
	if(x<=91)
		return "light heavy";
	return "heavy";
}

int main()
{
	for(double x;cin>>x;cout<<solve(x)<<endl)
		;
	
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstring>

using namespace std;

int main()
{
    int len = 1;
    int n;
    cin >> n;
    char *s = new char[n + 1];
    cin >> s;

    for (int i = 1; i < n; i++) {
        if (s[i] != s[i - 1]) {
            len++;
        }
    }

    cout << len << endl;

    return 0;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

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 (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N, K, L, R;
	cin >> N >> K >> L >> R;

	vector<ll> a(N);
	rep(i, 0, N)
	{
		cin >> a[i];
	}

	vector<vector<ll>> va(N + 1), vb(N + 1);
	va[0].pb(0);
	vb[0].pb(0);

	rep(i,0,N/2)
	{
		rrep(k, 0, K)
		{
			rep(j, 0, SZ(va[k]))
			{
				va[k + 1].pb(va[k][j] + a[i]);
			}
		}
	}

	rep(i, N / 2, N)
	{
		rrep(k, 0, K)
		{
			rep(j,0,SZ(vb[k]))
			{
				vb[k + 1].pb(vb[k][j] + a[i]);
			}
		}
	}

	int ans = 0;
	rep(k, 0, K + 1)
	{
		sort(all(va[k]));
		sort(all(vb[K - k]));
		rep(j,0,SZ(va[k]))
		{
			ans += (upper_bound(all(vb[K - k]), R - va[k][j]) - lower_bound(all(vb[K - k]), L - va[k][j]));
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 23556
import sys
myin = [x.rstrip() for x in sys.stdin.readlines()]

n = int(myin[0])
a = [int(x) for x in myin[1].split()]

cnt = [0] * (n+1)
for v in a:
    cnt[v] += 1

tmp = 0
for c in cnt:
    tmp += c * (c-1) // 2
for v in a:
    print(tmp - cnt[v] + 1)

Measured memory_bytes: 26000
# INPUT
n, k = map(int, input().split())

# # PROCESS
answer = 0
memo = 0
only_even = 0
for i in range(1, n+1):
  if k % 2 == 0:
    if i % k == 0:
      memo += 1
    if i % k == k/2:
       only_even += 1
  else:
    if i % k == 0:
      memo += 1

answer = memo * memo * memo
answer += only_even * only_even * only_even
# # OUTPUT
print(answer)

Measured memory_bytes: 3064
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{
    public void Proc()
    {
        int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).OrderByDescending(a=>a).ToArray();

        int ans = inpt[0] * 10 + inpt[1] + inpt[2];
        ans = Math.Max(inpt[0] + (inpt[1] * 10) + inpt[2], ans);
        Console.WriteLine(ans);
    }


    public class Reader
    {
        static StringReader sr;
        public static bool IsDebug = false;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (sr == null)
                {
                    sr = new StringReader(InputText.Trim());
                }
                return sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        private static string InputText = @"



6 6 7



";
    }

    public static void Main(string[] args)
    {
#if DEBUG
        Reader.IsDebug = true;
#endif
        Program prg = new Program();
        prg.Proc();
    }
}


Measured memory_bytes: 13396
n = int(input())

red =  [list(map(int,input().split())) for i in range(n)]
blue = [list(map(int,input().split())) for i in range(n)]

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

c = 0

for b in blue:
    for r in red:
        if r[0] < b[0] and r[1] < b[1]:
            c += 1
            red.remove(r)
            break
    
print(c)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
string s[1005];
struct Node {
    int x, y;
};
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};
int main() {
    int m, n; cin>>m>>n;
    for(int i=0; i<m; i++) cin>>s[i];
    queue<Node> q, q2;
    for(int i=0; i<m; i++) {
        for(int j=0; j<n; j++) {
            if(s[i][j] == '#') {
                Node t;
                t.x = i;
                t.y = j;
                q.push(t);
            }
        }
    }
    int sum = 0;
    while(!q.empty()) {
        while(!q.empty()) {
            Node t = q.front(); q.pop();
            for(int i=0; i<4; i++) {
                int nx = t.x + dx[i];
                int ny = t.y + dy[i];
                if(nx>=0&&nx<m&&ny>=0&&ny<n&&s[nx][ny]=='.') {
                    s[nx][ny] = '#';
                    Node t2;
                    t2.x = nx; t2.y = ny;
                    q2.push(t2);
                }
            }
        }
        q = q2;
        while(!q2.empty()) q2.pop();
        if(!q.empty()) sum++;
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 9600
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_mut)]
#[allow(non_snake_case)]
fn main() {
    input!{
        N: usize,
        A: i32,
        B: i32, 
        C: i32,
        l: [i32; N],
    }

    let mut min_cost = 1000000;
    let mut cost: i32;
    let mut out: usize;
    let mut Ac: i32;
    let mut Bc: i32;
    let mut Cc: i32;

    for ind in 0..4_usize.pow(N as u32) {
        Ac = 0;
        Bc = 0;
        Cc = 0;
        cost = 0;
        out = ind;
        for l_ind in 0..N {
            match out % 4 {
                0 => (),  
                1 => { 
                    Ac += l[l_ind];
                    cost += 10;
                },
                2 => {
                    Bc += l[l_ind];
                    cost += 10;
                },
                3 => {
                    Cc += l[l_ind];
                    cost += 10;
                },

                _ => panic!()
            }
            out /= 4
        }

        if Ac == 0 || Bc == 0 || Cc == 0 {
            continue;
        } else {
            cost += (Ac - A).abs() + (Bc - B).abs() + (Cc - C).abs();
            cost -= 30;
            if min_cost > cost {
                min_cost = cost;
            }
        }
    }




    println!("{}", min_cost);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int N = 1e5 + 5;
int n, k;
int a[N];
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> n >> k;
    for(int i = 1; i <= n; i++) cin >> a[i];
    int p = lower_bound(a + 1, a + n + 1, 0) - a - 1;
    int left = max(1, p - k + 1);
    int ans = INF;
    while(left <= p + 1) {
        int right = left + k - 1;
        if(right > n) break;
        if(a[right] < 0) {
            ans = min(ans, -a[left]);
        } else if(a[left] > 0) {
            ans = min(ans, a[right]);
        } else {
            int res = -a[left];
            ans = min(ans, min(2 * res + a[right], 2 * a[right] + res));
        }
        ++left;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 640
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from collections import deque

# N: ノードの数
# Q: 数値をノードに付与する回数
N, Q = map(int, input().split())

links =  [[] for _ in range(N)]
values = [0] * N

for i in range(N - 1):
    edge1, edge2 = [x - 1 for x in map(int, input().split())]
    links[edge1].append(edge2)
    links[edge2].append(edge1)

for i in range(Q):
    node, val = map(int, input().split())
    values[node - 1] += val

# 値の計算
stack = deque()
stack.append((0, -1))
while stack:
    node = stack.pop()

    for linked_node in links[node[0]]:
        if linked_node == node[1]:  # link が親ノード向けでなければ
            continue

        values[linked_node] += values[node[0]]
        stack.append((linked_node, node[0]))

print(*values)

Measured memory_bytes: 62232
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
//const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;



ll dp[103][100010];

int main()
{

    fastread();

    ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r;



      cin>>n>>k;


     vector<pll>v;

     v.eb(-1,-1);

     for(i=0; i<n; i++)
     {
         cin>>a>>b;

         v.eb(a,b);
     }
     sort(vll(v));

       for(i=1; i<=n; i++)
       {
           for(j=1; j<=k; j++)
           {

               if(v[i].F>j)
               {
                   dp[i][j]=dp[i-1][j];

               }
             else dp[i][j]=max(dp[i-1][j],dp[i-1][j-v[i].F]+v[i].S);


           }
          // cout<<endl;
       }

       cout<<dp[n][k]<<endl;




}



Measured memory_bytes: 81752
#include <iostream>
#include <sstream>
#include <cstdio>
#include <stdlib.h>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define max 1001
int n,c[max][max];
string x,y;
void SerchMinStr(){
  int i,j,ans,k;
  for(i=1;i<(int)x.length()+1;i++){
    for(j=1;j<(int)y.length()+1;j++){
      if(x[i-1]==y[j-1]){c[i][j]=c[i-1][j-1]+1;}
      else if(c[i-1][j]>=c[i][j-1])c[i][j]=c[i-1][j];
      else c[i][j]=c[i][j-1];
    }
  }
  i--;j--;
  ans=c[i][j];

  for(k=1;k<(int)x.length();k++)
    if(ans<c[k][j])ans=c[k][j];
  for(k=1;k<(int)y.length();k++)
    if(ans<c[i][k])ans=c[i][k];
  cout<<ans<<endl;
}
int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>x>>y;
    SerchMinStr();
  }  
  return 0;
}



Measured memory_bytes: 7064
const main = (input) => {
  var s = input[0];
  var ans = "";
  switch(s){
    case "Sunny":
      ans = "Cloudy";
      break;
    case "Cloudy":
      ans = "Rainy";
      break;
    case "Rainy":
      ans = "Sunny";
      break;
  }
  console.log(ans);
}
main(require('fs').readFileSync('/dev/stdin', 'UTF-8').trim().split("\n"));


Measured memory_bytes: 22076
K, A, B = map(int, input().split())

if A + 2 >= B or K <= A:
    print(K + 1)
else:
    ans = A
    rem_times = K - (A - 1)
    if rem_times % 2 != 0:
        ans += 1
        rem_times -= 1
    ans += (B - A) * (rem_times // 2)
    print(ans)

Measured memory_bytes: 3060
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    String S =sc.next();
    String s[] =S.split("",0);
    int N =S.length();
    int t[] =new int[N];
    int x=0;int y=0;
    for(int i=0;i<N;i++){
      t[i]=Integer.parseInt(s[i]);
      if(t[i]==0){x=x+1;}
      else{y=y+1;}
    }
    int z =Math.min(x,y);
    System.out.println(z*2);
  }
}

Measured memory_bytes: 32188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll h1,m1,h2,m2,k;
	cin>>h1>>m1>>h2>>m2>>k;
	ll t=((h2-h1)*60)-m1+m2;
	ll d=t-k;
	if(d<=0){
		cout<<"0"<<"\n";
	}
	else{
		cout<<d<<"\n";
	}
	return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

ll dp[100005][3];

int main(void){
  ll n;
  cin >> n;
  vector<ll> a(n), b(n), c(n);
  REP(i, n) cin >> a[i] >> b[i] >> c[i];
  REP(i, n){
    dp[i+1][0] = max(dp[i][1]+b[i], dp[i][2]+c[i]);
    dp[i+1][1] = max(dp[i][0]+a[i], dp[i][2]+c[i]);
    dp[i+1][2] = max(dp[i][0]+a[i], dp[i][1]+b[i]);
  }
  ll ans = 0;
  REP(i, 3) chmax(ans, dp[n][i]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 7896
using System;
using System.Linq;
using System.Collections.Generic;

namespace b
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var p = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();

            var l = 0;
            for(var i = 0; i < n; i++){
                if(p[i] != i + 1){
                    l++;
                }
            }

            if(l > 2){
                Console.WriteLine("NO");
            }else{
                Console.WriteLine("YES");
            }
        }
    }
}


Measured memory_bytes: 11348
#include <bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

ll gcd(ll a, ll b) { return b?gcd(b, a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a, b)*b;}
const int IINF=(1<<30);
const ll LLINF = 1LL<<60;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  int n, m; cin >> n >> m;
  vector<char> hoge(n);
  int s;
  char c;
  for (int i = 0; i < m; i++){
    cin >> s >> c;
    if (hoge[s - 1] != 0)
    {
      if(hoge[s - 1] != c)
      {
        cout << "-1" << endl;
        return 0;
      }
    }
    hoge[s - 1] = c;
  }
  if(n == 1){
    if(m == 0){
      cout << "0" << endl;
      return 0;
    }
    cout << hoge[0] << endl;
    return 0;
  }else{
    if(hoge[0] == '0'){
      cout << "-1" << endl;
      return 0;
    }else{
      for (int i = 0; i < hoge.size(); i++){
        if(hoge[i] == 0){
          if(i == 0){
            hoge[i] = '1';
          }else{
            hoge[i] = '0';
          }
        }
      }
    }
  }
  string S;
  for (int i = 0; i < hoge.size(); i++){
    S += hoge[i];
    // cout << hoge[i] << endl;
  }
  cout << S << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lli long long int
#define uli unsigned long long int
#define inf 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define per(i,m,n) for(lli i=m-1;i>=n;i--)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
using namespace std;
int main(){
  int n,a,b,x,y;
  string s,t,r;
  cin>>n>>s>>t;
  rep(i,0,n){
    r+=s.at(i);
    r+=t.at(i);
  }
  cout<<r<<endl;
}

Measured memory_bytes: 256
// たなこふ先生の input マクロ (´･_･`)
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::collections::BTreeMap;

fn get_prime_factors(n: usize) -> BTreeMap<usize, usize> {
    let mut prime_factors = BTreeMap::new();

    let mut m = n;

    for f in (2..).take_while(|a| a*a <= n) {
        let mut i = 0;
        while m % f == 0 {
            i = i+1;
            m = m / f;
        }
        if i > 0 {
            prime_factors.insert(f, i);
        }
    }

    if m > 1 {
        prime_factors.insert(m, 1);
    }

    prime_factors
}

fn main() {
    input! {
        n: usize,
    }

    let mut count_primes = BTreeMap::<usize, usize>::new();

    for i in 1..n+1 {
        for (p, k) in get_prime_factors(i) {
            *count_primes.entry(p).or_insert(0) += k;
        }
    }

    let mut facts = vec![1];

    let mut fact = |n: usize| -> usize {
        let l = facts.len();
        if n >= l {
            facts.reserve(n + 1 - l);
            for i in l..n+1 {
                let f = facts[i-1];
                facts.push(f*i);
            }
        }
        facts[n]
    };

    let mut comb = |n: usize, r: usize| -> usize {
        if r > n {
            0
        } else {
            fact(n) / (fact(n-r) * fact(r))
        }
    };

    let pf74 = count_primes.iter().filter(|&(_p, k)| *k>=74).count();
    let pf24 = count_primes.iter().filter(|&(_p, k)| *k>=24).count();
    let pf14 = count_primes.iter().filter(|&(_p, k)| *k>=14).count();
    let pf4 = count_primes.iter().filter(|&(_p, k)| *k>=4).count();
    let pf2 = count_primes.iter().filter(|&(_p, k)| *k>=2).count();
    let c25_3 = pf24 * pf2.saturating_sub(1);
    let c15_5 = pf14 * pf4.saturating_sub(1);
    let c5_5 = comb(pf4, 2);
    let c5_5_2 = c5_5 * pf2.saturating_sub(2);

    println!("{}", pf74 + c25_3 + c15_5 + c5_5_2);
}


Measured memory_bytes: 4352
#![allow(non_snake_case)]
#![allow(unused_imports)]
#![allow(dead_code)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;


#[fastout]
fn solve() {
    const MOD: usize = 1_000_000_007;
    const INF: usize = std::usize::MAX;
    
    input!{
        n: usize,
        s: Chars,
    }

    let mut cnt_vec: Vec<(usize, usize)> = vec![(0, 0)];

    for i in 0..n {
        let (e, w) = cnt_vec.last().unwrap();
        if s[i] == 'W' {
            cnt_vec.push((*e, *w+1))
        } else {
            cnt_vec.push((*e+1, *w));    
        }
    }

    let mut ans = INF;

    for i in 0..n {
        let t = cnt_vec[i].1 + cnt_vec[cnt_vec.len()-1].0 - cnt_vec[i+1].0;
        ans = std::cmp::min(ans, t);
    }

    println!("{}", ans);
}

fn main() {
    solve()
}

#[cfg(test)]
mod test {
    use super::solve;
}


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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }


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

    string ans = "";
    rep(i,s.size())
    {
        if( s[i] == '0' ) ans.push_back('0');
        else if( s[i] == '1' ) ans.push_back('1');
        else if( ans != "" ) ans.erase(ans.end()-1);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <ctime>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iterator>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	for(vi a(5),b(5);cin>>a[0]>>b[0],a[0]|b[0];){
		repi(i,1,5) cin>>a[i]>>b[i];
		rep(i,5) a[i]+=b[i];
		int res=max_element(allof(a))-a.begin();
		cout<<char('A'+res)<<" "<<a[res]<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;
int n;

bool check(vector<int> &p) {
    vector<int> q(n);
    iota(q.begin(), q.end(), 1);
    rep(i,n) if (p[i]!=q[i]) return false;
    return true;
}

bool once_swap(int i, int j, vector<int> p) {
    swap(p[i],p[j]);
    return (check(p));
}

int main(int argc, char const *argv[]) {
    cin>>n;
    vector<int> p(n);
    rep(i,n) cin>>p[i];

    for (int i = 0; i < n; ++i) {
        for (int j = i; j < n; ++j) {
            if (once_swap(i,j,p)) {
                cout << "YES" << endl;
                return 0;
            }
        }
    }

    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 100010
#define ll long long
#define inf 1e9
#define M 1000000007
#define pii pair<ll, ll>

using namespace std;
map <int,int>mp;
ll mulmod(ll a,ll b,ll c)
{
	return ((((a>>20)*b%c)<<20)+(a&((1<<(20))-1))*b)%c;
}
ll moddexp(ll a, ll b)//This function calculates a to the power b mod M
{
    ll res=1,y=a;
    while(b>0)
    {
        if(b&1)
            res=mulmod(res,y,M);
        y=mulmod(y,y,M);
        b/=2;
    }
    return res;
}
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        mp[x]++;
    }
    if(n&1)
    {
        int c=0;
        for(auto it=mp.begin();it!=mp.end();it++)
        {
            int temp=(*it).first;
            if(temp!=c)
                {
                    cout<<0<<endl;
                    return 0;
                }
            if(c)
            {
                if(mp[temp]!=2)
                {
                    cout<<0<<endl;
                    return 0;
                }
            }
            else
            {
                if(mp[temp]!=1)
                {
                    cout<<0<<endl;
                    return 0;
                }
            }
            c+=2;
        }
    }
    else
    {
        int c=1;
        for(auto it=mp.begin();it!=mp.end();it++)
        {
            int temp=(*it).first;
            if(temp!=c)
            {
                cout<<0<<endl;
                return 0;
            }
            if(mp[temp]!=2)
            {
                cout<<0<<endl;
                return 0;
            }
            c+=2;
        }
    }

        ll temp=n/2;
        ll ans=moddexp(2,temp);
        cout<<ans<<endl;

    return 0;
}


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

int n,r;
int s,t;
int deck1[50],deck2[50];

void shuffle(int p,int c);

int main()
{
        while(cin >> n >> r){
                if(n==0 && r==0) break;
                for(int i=0;i<n;i++){
                        deck1[i] = n-i;
                }

                for(int i=0;i<r;i++){
                        cin >> s >> t;
                        shuffle(s,t);
                }

                cout << deck1[0] << endl;
        }

        return 0;
}

void shuffle(int p,int c)
{
        for(int i=0;i<c;i++) deck2[i] = deck1[p-1+i];
        for(int i=0;i<p-1;i++) deck2[c+i] = deck1[i];
        for(int i=0;i<c+p-1;i++) deck1[i] = deck2[i];
}

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

int main() {
  int input;

  cin >> input;
  
  int first = input / 100;
  int second = (input - first * 100) / 10;
  int third = input - first * 100 - second * 10;

  cout << first + second + third << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main (String [] args) {

        Scanner sc = new Scanner(System.in);
        sc.nextInt();
        double [] circa = new double[3];
        double [] circb = new double[3];

        while (sc.hasNext()) {
            int res = 1;

            for (int i = 0; i < 3; i++ ){
                circa[i] = sc.nextDouble();
            }
            for (int i = 0; i < 3; i++ ){
                circb[i] = sc.nextDouble();
            }

            double dist = Math.sqrt( (circa[0] - circb[0]) * (circa[0] - circb[0]) + (circa[1] - circb[1]) * (circa[1] - circb[1]) );
            
            if ( dist > circa[2] + circb[2] ) {
                res = 0;
            } else if ( dist + circb[2] < circa[2] ) {
                res = 2;
            } else if ( dist + circa[2] < circb[2] ) {
                res = -2;
            }

            System.out.println(res);
        }

    }
}

Measured memory_bytes: 12000
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
int main(){
  int N,X;
  cin >> N >> X;
  vector<int> vec(N);
  for(int i = 0;i < N;++i){
    cin >> vec[i];
    X -= vec[i];
  }
  sort(vec.begin(),vec.end());
  cout << N + X/vec[0] <<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
    ll n,k;
    cin>>n>>k;
    ll arr[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    ll dp[n+1];
    for(int i=0;i<=n;i++){
        dp[i]=INT_MAX;
    }
    dp[0]=0;
    dp[1]=0;
    for(int i=2;i<=n;i++){
        for(int j=i-1;j>i-k-1 && j>=0; j--){
          dp[i]= min(dp[i], abs(arr[i-1]-arr[j-1]) + dp[j]);
        }
        }

    cout<<dp[n];
return 0;
}


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

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
typedef long long ll;
using namespace std;
int N;
int main() {
	cin>>N;
	vector <int> A(N), B(N);
	for(ll i=0;i<N;i++){
		cin>>A[i];
		B[i]=A[i];
	}
	sort(B.begin(), B.end(), greater<int>());

	for(ll i=0;i<N;i++){
		if(B[0]==A[i]){
			cout<<B[1]<<endl;
		}else{
			cout<<B[0]<<endl;
		}
	}


	return 0;
}


Measured memory_bytes: 3200
import sys


class Node:
    def __init__(self, key, prev, next):
        self.key = key
        self.prev = prev
        self.next = next


class LinkedList:
    def __init__(self):
        self.nil = Node(None, None, None)
        self.nil.prev = self.nil
        self.nil.next = self.nil


def insert(double_lst, key):
    node = Node(key, double_lst.nil, double_lst.nil.next)
    double_lst.nil.next.prev = node
    double_lst.nil.next = node


def search(double_lst, key):
    cur = double_lst.nil.next

    while cur != double_lst.nil and cur.key != key:
        cur = cur.next

    return cur


def delete_node(double_lst, node):
    if node == double_lst.nil:
            return

    node.prev.next = node.next
    node.next.prev = node.prev


def delete_first(double_lst):
    delete_node(double_lst, double_lst.nil.next)


def delete_last(double_lst):
    delete_node(double_lst, double_lst.nil.prev)


def delete_key(double_lst, key):
    node = search(double_lst, key)
    delete_node(double_lst, node)


def main():
    n = int(input())
    ll = LinkedList()

    for i in range(n):
        order = sys.stdin.readline().split()

        if order[0] == "insert":
            insert(ll, int(order[1]))
        elif order[0] == "delete":
            delete_key(ll, int(order[1]))
        elif order[0] == "deleteFirst":
            delete_first(ll)
        else:
            delete_last(ll)

    cur = ll.nil
    while cur.next != ll.nil:
        cur = cur.next
        if cur.next == ll.nil:
            print(cur.key)
        else:
            print(cur.key, end=" ")


if __name__ == '__main__':
    main()



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

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

Measured memory_bytes: 256
n=int(input())

def make_divisors(n):
    divisors = []
    for i in range(int(n**0.5)+1, 0, -1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
            return divisors

    # divisors.sort()
    return divisors


k=make_divisors(n)
if len(k)==2:
    print(sum(k)-2)
else:
    print(k.pop()*2-2)

Measured memory_bytes: 3188
#include <iostream>

#define REP(i, a, b) for ( int i = (a); i < (b); i++ )
#define REVREP(i, a, b) for ( int i = (a); i >= (b); i--)
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)

using namespace std;

int H, W, A, B;
int s[1005][1005];

int main(void) {
    scanf("%d %d %d %d", &H, &W, &A, &B);

    REP(i, 0, B) {
    	REP(j, 0, W) {
    		if (j < A) s[i][j] = 1;
    		else s[i][j] = 0;
    	}
    }

    REP(i, B, H) {
    	REP(j, 0, W) {
    		if (j < A) s[i][j] = 0;
    		else s[i][j] = 1;
    	}
    }

    REP(i, 0, H) {
    	REP(j, 0, W) {
    		printf("%d", s[i][j]);
    	}
    	printf("\n");
    }

	return 0;
}


Measured memory_bytes: 5120
#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rrep(i, n) for(int i=(n-1); i>=0; --i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define print(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define print(...)
#endif

int main(int argc, const char * argv[]) {
	std::cout << std::fixed << std::setprecision(15);

	ll A, B, C; cin >> A>> B >> C;
	ll K; cin >> K;
	ll ans = 0;
	if(K > 0){
		ans += min(A, K);
		K -= A;
	}

	if(K > 0){
		K -= B;
	}

	if(K > 0){
		ans -= min(C, K);
		K -= C;
	}

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


Measured memory_bytes: 3632
def main():
    N, X, T = map(int, input().split())

#一度にMAX X
    if N <= X :
        print(T)
    else:
        time = 0
        if N % X == 0:
            time = T * (N//X)
        else:
            time = T * (N//X) + T
        print(time)
main()


Measured memory_bytes: 9160
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;
long long int INF = 1e18;

long long int DP1[150000], DP2[150000];

int main(){
	while(true){
		int n, m;
		cin >> n;
		
		if(n == 0){
			break;
		}
		
		int HP[200];
		
		for(int i = 0; i < n; i++){
			cin >> HP[i];
		}
		
		for(int i = 0; i < 110000; i++){
			DP1[i] = INF;
			DP2[i] = INF;
		}
		
		DP1[0] = 0;
		DP2[0] = 0;
		
		cin >> m;
		
		for(int i = 0; i < m; i++){
			long long int cost, D;
			string hoge, t;
			cin >> hoge >> cost >> t >> D;
			if(t == "Single"){
				for(int j = 0; j < 110000; j++){
					DP1[j] = min(DP1[j], DP1[max(0LL, j - D)] + cost);
				}
			}else{
				for(int j = 0; j < 110000; j++){
					DP2[j] = min(DP2[j], DP2[max(0LL, j - D)] + cost);
				}
			}
		}
		
		long long int ans = INF;
		for(int i = 0; i < 110000; i++){
			long long int ret = DP2[i];
			for(int j = 0; j < n; j++){
				ret += DP1[max(0, HP[j] - i)];
				if(ret >= INF){
					break;
				}
			}
			ans = min(ans, ret);
		}
		cout << ans << endl;
	}
	return 0;
}




Measured memory_bytes: 4880