akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <utility>
using namespace std;

#define MOD 1000000007
#define INF 1e9+7
#define rep(i, n) for(int i=0; i<n; ++i)
#define rrep(i, m, n) for(int i=m; i<n; ++i)
typedef long long ll;

#define MAX_N 1000
#define MAX_M 100000
#define MAX_V 100
#define MAX_E 100
#define MAX_Q 100000

int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};

int ddx[] = {-1, 0, 1, 0, -1, 1, -1, 1};
int ddy[] = {0, -1, 0, 1, 1, 1, -1, -1};

//--------------------------



int main() {

  double n;
  double odds = 0;

  cin >> n;

  for(int i=1; i<=n; ++i) {
    if(i%2==1) ++odds;
  }

  cout << fixed;
  cout << setprecision(7) << odds/n << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<sstream>
#include<vector>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)
#define FOR(i, j, k) for(int i = j; i < k; i++)
const int N = 30;

bool isOK(string str){
    stringstream ss(str);
    vector<string> v;
    string tmp;
    while(ss >>tmp) v.push_back(tmp);
    REP(i, v.size()) if(v[i] == "the" || v[i] == "this" || v[i] == "that") return true;
    return false;
}

int main(){
    string str;
    while(getline(cin, str)){
        REP(z, N){
            REP(i, str.size()){
                if(!isalpha(str[i])) continue;
                str[i] = ++str[i] <= 'z'? str[i] : 'a';
            }
            if(isOK(str)){
                cout <<str <<endl;
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1208
#include<iostream>
using namespace std;
typedef long long ll;
int main(){
	ll k;
	cin >> k;
	if(k==0){
		cout << 2 << endl;
		cout << 1 << " " << 1 << endl;
		return 0;
	}
	ll a=50+(k-1)/50;
	int b=(k-1)%50;
	cout << "50" << endl;
	for(int i=0;i<50;i++){
		if(i!=0) cout << " ";
		cout << a-i-(b<i?1:0);
	}
	cout << endl;
	return 0;
}


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

int main()
{
    bool flg[11] = {false};
    for(int i = 0; i < 4; ++i) {
        int tmp;
        cin >> tmp;
        flg[tmp] = true;
    }
    if(flg[1] && flg[9] && flg[7] && flg[4]) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<ios>
using namespace std;
int n;
int f(char c)
{
	if(c<='9')return c-'0';
	else return c-'a'+10;
}
main()
{
	cin>>n;
	for(;n--;)
	{
		string s;cin>>s;
		bool hugou=0;
		int d;
		double a;
		hugou=f(s[0])/8;
		d=f(s[0])%8;
		for(int i=1;i<=5;i++)
		{
			d=d*16+f(s[i]);
		}
		d=d*2+f(s[6])/8;
		a=f(s[6])%8*16+f(s[7]);
		if(hugou)cout<<'-';
		if(a==0)cout<<d<<".0";
		else printf("%.15g",d+a/128);
		cout<<endl;
	}
}



Measured memory_bytes: 3288
from collections import deque
def main():
    n,x,y = map(int,input().split())
    cnt = [0]*n
    for i in range(n):
        d = [float('inf')]*n
        que = deque([(i, 0)])
        while que:
            idx, c = que.popleft()
            if d[idx]!=float('inf'):
                d[idx] = min(d[idx], c)
                continue
            else:
                d[idx] = min(d[idx], c)
                if idx!=0:
                    que.append((idx-1, c+1))
                if idx!=n-1:
                    que.append((idx+1, c+1))
                if idx==x-1:
                    que.append((y-1, c+1))
                if idx==y-1:
                    que.append((x-1, c+1))
        for j in range(i+1, n):
            cnt[d[j]] += 1
    for c in cnt[1:]:
        print(c)
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 70236
#include <bits/stdc++.h> 
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
#define MAX 100005
#define DEBUG 0 
#define LIMIT (LONG_MAX / 10)
#define POSITIVE_LAST_D (LONG_MAX % 10)
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;

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

    int a,b;
    cin>>a>>b;

    string u;
    cin>>u;

    if(s==u){
        cout<<a-1<<" "<<b<<endl;
    }else{
        cout<<a<<" "<<b-1<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;



public class Main {

//    public static void gyo1(int w2, int number){
//        if ( w2 == 1) {
//            for (int a = 0; a < number; a++) {
//                System.out.printf("#.");
//            }
//            System.out.printf("#");
//        } else {
//            for (int a = 0; a < number; a++) {
//                System.out.printf("#.");
//            }
//        }
//        System.out.printf("\n");
//    }
//
//    public static void gyo2(int n, int number){
//        if ( n == 1) {
//            for (int a = 0; a < number ; a++) {
//                System.out.printf(".#");
//            }
//            System.out.printf(".");
//        } else {
//            for (int a = 0; a < number; a++) {
//                System.out.printf(".#");
//            }
//        }
//        System.out.printf("\n");
//    }


    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        while(true) {
            int H = input.nextInt();
            int W = input.nextInt();
            if (H == 0 && W == 0) {
                break;
            }
            int w2 = W % 2;
            for (int i = 0; i < H; i = i + 1) {
                if (i % 2 == 0) {
                    if ( w2 == 1) {
                        for (int a = 0; a < W / 2; a++) {
                            System.out.printf("#.");
                        }
                        System.out.printf("#");
                    } else {
                        for (int a = 0; a < W / 2; a++) {
                            System.out.printf("#.");
                        }
                    }
                    System.out.printf("\n");
                    continue;
                }
                if ( w2 == 1) {
                    for (int a = 0; a < W /2 ; a++) {
                        System.out.printf(".#");
                    }
                    System.out.printf(".");
                } else {
                    for (int a = 0; a < W / 2 ; a++) {
                        System.out.printf(".#");
                    }
                }
                System.out.printf("\n");
            }
            System.out.printf("\n");
            // }
            //第一行目の”＃. # .”

        }
    }

}


Measured memory_bytes: 55640
/*
    ##############################
    #  Author: Pratyush Gaurav   #
    #  College: NIT ROURKELA     #
    ##############################
*/
#include <bits/stdc++.h>

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli > plli;
typedef vector<lli> vlli;
typedef vector<plli > vplli;

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a * b) / gcd(a, b))
#define sqr(x) (x)*(x)
#define all(a) a.begin(),a.end()
#define UN(v) sort(all(v)), v.resize(unique(all(v))-v.begin())

#define endl '\n'

const long long INF = 100000000000000000;
const long long MOD = 1000000007;
const long long MAXN = 100005;

lli dx[]={0,0,-1,1,-1,-1,1,1};
lli dy[]={1,-1,0,0,1,-1,-1,1};

void solve() {
    lli n, k;
    cin >> n >> k;
    vlli v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    sort(all(v));
    lli ans = INF;
    for (int i = 0; i < n - k + 1; ++i) {
        ans = min(ans, v[i + k - 1] - v[i]);
    }
    cout << ans << endl;
}

int main()
{
    IOS;
    lli t = 1;
    //cin >> t;

    while(t--)
        solve();
    return 0;
}

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

int main()
{
	int d, g;
	cin >> d >> g;
	vector<int> p(d), c(d);
	for (int i = 0; i < d; i++)
		cin >> p[i] >> c[i];
	int ans = 0;
	for (int i = 0; i < d; i++)
		ans += p[i];
	for (int i = 0; i < (1 << d); i++)
	{
		int temp = 0, numOfProblems = 0, maxRest = -1;
		for (int j = 0; j < d; j++)
		{
			if (i >> j & 1)
			{
				temp += (j + 1) * 100 * p[j] + c[j];
				numOfProblems += p[j];
			}
			else
				maxRest = j;
		}
		if (temp < g)
		{
			int score = (maxRest + 1) * 100;
			int need = (g - temp + score - 1) / score;
			if (need >= p[maxRest])
				continue;
			numOfProblems += need;
		}
		ans = min(ans, numOfProblems);
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
use std::fmt::Display;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn print_vec<T: Display>(a: &Vec<T>, n: usize) {
    for i in 0..n {
        print!("{}", a[i]);
        if i == n - 1 {
            println!("");
        } else {
            print!(" ");
        }
    }
}

fn selection_sort<T: Ord + Copy>(a: &mut Vec<T>, n: usize) -> u32 {
    let mut cnt: u32 = 0;
    for i in 0..n {
        let mut minj = i;
        for j in i..n {
            if a[j] < a[minj] {
                minj = j;
            }
        }
        if i != minj {
            let tmp = a[i];
            a[i] = a[minj];
            a[minj] = tmp;
            cnt += 1;
        }
    }
    cnt
}

fn main() {
    let n: usize = read();
    let mut a: Vec<i32> = read_vec();

    let c = selection_sort(&mut a, n);

    print_vec(&a, n);

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



Measured memory_bytes: 5040
#include <bits/stdc++.h>
using namespace std;
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; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }

vector<int> v = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); 

    int K;
    while (cin >> K) {
        cout << v[K-1] << endl;
    }
}


















Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
void bitserch(vector<long> v,long depth,long goal,long Wf,long Kf, long &C,vector<string> &Sf) {
	if (depth==goal) {
		vector<long> wcnt(v.size());
		long zanntei = 0;
		long far = -1;
		long white=0;
		long nozero = (v[0] != 0) ? 1 : 0;
		for (int i=1;i<v.size();i++)
		{
			nozero+= (v[i] != v[i-1]) ? 1 : 0;
		}
		for (int i = 0; i < Wf; i++)
		{
			for (int m = 0; m < v.size(); m++)
			{
				int flg = 1;
				wcnt[v[m]] += (Sf[m][i] == '1') ? 1 : 0;
				if (wcnt[v[m]] > Kf) 
				{
					if (far == i-1)
						return;
					wcnt = vector<long>(v.size());
					i = i - 1;//far;
					far = i ;
					zanntei++;
					break;
				}
			}
		}
		C = min(nozero + zanntei, C);
		return;
	}
	auto w = v;
	v.push_back(depth);
	w.push_back(w[w.size()-1]);
	bitserch(v, depth + 1,goal,Wf,Kf,C,Sf);
	bitserch(w, depth + 1,goal,Wf,Kf,C,Sf);
}
int main()
{
	long H, W, K,count;
	cin >> H >> W >> K;
	vector<string> S(H);
	vector<long> V(1);
	for (string& s : S) {
		cin >> s;
	}
	count = H+W;//(H - 1) * (W - 1);
	bitserch(V, 1, H, W, K, count, S);
	cout << count;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

using namespace std;

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

	int A, B, C, K;
	cin >> A >> B >> C >> K;

	int result = 0;
	int leftK = K;

	int value1 = min(leftK, A);
	leftK -= value1;
	result += value1;
	if (leftK <= 0)
	{
		cout << result;
		return 0;
	}

	leftK -= min(leftK, B);
	if (leftK <= 0)
	{
		cout << result;
		return 0;
	}

	int value2 = min(leftK, C);
	leftK -= value2;
	result -= value2;

	cout << result;

	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n-1); i >= 0; i--)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<62;
const int IINF = 1000000000;
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; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;

int main(){
    int N; cin >> N;
    vector<vector<int>> A(N, vector<int>(N));
    vector<vector<bool>> exists(N, vector<bool>(N, true));
    rep(i,N) rep(j,N) cin >> A[i][j];

    rep(k,N){
        rep(i,N){
            if (i == k) continue;
            rep(j,N){
                if (j == i || j == k) continue;
                if (A[i][k] + A[k][j] < A[i][j]){
                    cout << -1 << endl;
                    return 0;
                }
                /*
                if (A[i][k] + A[k][j] > A[i][j]){
                    exists[i][j] = true;
                }
                */
                if (A[i][k] + A[k][j] == A[i][j]){
                    exists[i][j] = false;
                }
                /*
                if (A[i][k] + A[k][j] > A[i][j] && i != k && k != j){
                    exists[i][j] = true;
                }
                */
            }
        }
    }

    ll ans = 0;
    rep(i,N){
        rep(j,N){
            if (exists[i][j]){
                ans += A[i][j];
            }
        }
    }
    cout << ans/2 << endl;
}

Measured memory_bytes: 4004
L = int(input())
n = L.bit_length()
path = []
tmp = 1
for i in range(1, n):
    path.append((n-i, n-i+1, 0))
    path.append((n - i, n - i + 1, tmp))
    tmp *= 2
    if (L >> (n - i - 1)) & 1:
        path.append((n - i, n, tmp))
        tmp += 1
print(n, len(path))
for p in path[::-1]:
    print(' '.join(map(str, p)))


Measured memory_bytes: 61552
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

int main (void){
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b && b == c && c == a){
        cout << "No" << endl;
    } else if (a == b || b == c || c == a){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl; 
    }
    return 0;
}

Measured memory_bytes: 3604
import sys
from math import ceil
def input(): return sys.stdin.readline().strip()


def main():
    N, A, B = map(int, input().split())
    monster = [int(input()) for _ in range(N)]
    additional = A - B
    """
    Bの誘爆を基本に考えて決めうち二分探索を行う。
    """
    left = 0
    right = max(monster) // B + 1
    while right - left > 1:
        mid = (left + right) // 2
        times = 0
        for m in monster:
            times += max(0, ceil((m - B * mid) / additional))
        if times > mid:
            left = mid
        else:
            right = mid
    print(right)

if __name__ == "__main__":
    main()


Measured memory_bytes: 77384
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  long long count=0;
  for(int i=1;i<=N;i++){
  if(i%3!=0&&i%5!=0){
  
  count+=i;
  }
  }
cout<<count<<endl;
}


Measured memory_bytes: 3524
#include<bits/stdc++.h>
using namespace std;
long long k,xb,s,x=1;
inline double check(long long xx)
{
    long long ss=0,t=xx;
    while (xx>0)
    {
      ss+=xx%10;
      xx/=10;
    }
    return t*1.0/(ss*1.0);
}
int main()
{
    scanf("%lld",&k);
    while (xb<k)
      if ((s/x)%10!=9)
	  {
        s+=x;++xb;
        printf("%lld\n",s);
      }else
	  {
        if (check(s+x)>check(s+10*x))
          x*=10;
        s+=x;++xb;
        printf("%lld\n",s);
      }
    return 0;
}

Measured memory_bytes: 3816
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner scanner =new Scanner(System.in);
		int N = scanner.nextInt();
		int[] line = new int[N];
		int sum = 0;

		for (int i = 0; i < N; i++) {
			line[i] = scanner.nextInt();
			sum += line[i];
		}

		int y = (int)Math.round((double)sum/N);

		int ans = 0;
		for (int i = 0; i < N; i++) {
			ans += (line[i] - y)*(line[i] - y);
		}

		System.out.println(ans);

		scanner.close();
	}

}


Measured memory_bytes: 26980
n, q = map(int, input().split())
s = input()

memo = [0] * n
for i in range(n-1):
    if s[i+1] == 'C' and s[i] == 'A':
        memo[i+1] = 1

for i in range(n-1):
    memo[i+1] += memo[i]

for i in range(q):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    if l == 0:
        print(memo[r])
    else:
        print(memo[r] - memo[l])


Measured memory_bytes: 7668
function Main(input) {
    input = input.trim().split("\n").map(function(x) { return x.split(" ")});    
    var N = parseInt(input[0][0], 10);
    var vec_ans = Array.from({length: N}, () => 0);

    for (var i = 1; i <= Math.sqrt(N); i++){
        for (var j = i; j >= 1; j--){
            for (var k = j; k >= 1; k--){
                if (i === j && j===k) vec_ans[i * i + j * j + k * k + i * j + j * k + k * i - 1]++;
                else if (i === j || j === k) vec_ans[i * i + j * j + k * k + i * j + j * k + k * i - 1]+=3;
                else vec_ans[i * i + j * j + k * k + i * j + j * k + k * i - 1]+=6;
            }
        }
    }
    vec_ans.length = N;
    console.log(vec_ans.join("\n"));
}

Main(require("fs").readFileSync("/dev/stdin", "utf8")); 

Measured memory_bytes: 35416
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
arr = [0] * (N + 1)
arr[0], arr[N] = 0, 0
for i in A:
    arr[i] = 1
l, r = sum(arr[:X]), sum(arr[X + 1 :])
print(min(l, r))


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

#define ll          long long
#define pb          push_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
void solve(){
    ll a,b,k;
    cin>>a>>b>>k;
    ll temp=min(k,a);
    a-=temp;
    k-=temp;
    b-=min(b,k);
    cout<<a<<" "<<b;
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    time
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        if(n<=111){
            System.out.println("111");
        }
        else if(n<=222){
            System.out.println("222");
        }
        else if(n<=333){
            System.out.println("333");
        }
        else if(n<=444){
            System.out.println("444");
        }
        else if(n<=555){
            System.out.println("555");
        }
        else if(n<=666){
            System.out.println("666");
        }
        else if(n<=777){
            System.out.println("777");
        }
        else if(n<=888){
            System.out.println("888");
        }
        else if(n<=999){
            System.out.println("999");
        }
    }
}

Measured memory_bytes: 25300
package main

import (
	"fmt"
	"sort"
)

const MOD = 1000000007

func ModAdd(a, b int64) int64 {
	return (a + b) % MOD
}

func ModMul(a, b int64) int64 {
	return a * b % MOD
}

func ModSub(a, b int64) int64 {
	r := (a%MOD - b%MOD) % MOD
	if r < 0 {
		r += MOD
	}
	return r
}

func ModDiv(a, b int64) int64 {
	return a % MOD * ModInv(b) % MOD
}

func ModPow(a, n int64) int64 {
	var r int64 = 1
	for n > 0 {
		if n&1 == 1 {
			r = r * a % MOD
		}
		a = a * a % MOD
		n >>= 1
	}
	return r
}

func ModInv(a int64) int64 {
	var b, u, v int64 = MOD, 1, 0
	for b > 0 {
		t := a / b
		a -= t * b
		a, b = b, a
		u -= t * v
		u, v = v, u
	}
	u %= MOD
	if u < 0 {
		u += MOD
	}
	return u
}

type Q struct {
	idx, value int
	a, b       int
	index      int
}

type QS []*Q

func (p QS) Len() int           { return len(p) }
func (p QS) Less(i, j int) bool { return p[i].value > p[j].value }
func (pq QS) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *QS) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Q)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *QS) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

func main() {
	var N int
	fmt.Scanf("%d\n", &N)
	A := make([]int, N)
	M := make([]int, N)
	for i := 0; i < N; i++ {
		var a int
		fmt.Scan(&a)
		A[i] = a
		M[i] = a
	}
	sort.Sort(sort.Reverse(sort.IntSlice(M)))
	for _, a := range A {
		if M[0] == a {
			fmt.Println(M[1])
		} else {
			fmt.Println(M[0])
		}
	}
}

func Reverse(runes []rune) []rune {
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return runes
}


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

int bit_count( const int n )
{
	int cnt = 0;
	for ( int i = 0; i < 10; i++ )
	{
		if ( n & 1 << i ) cnt++;
	}
	return cnt;
}

int main( void )
{
	int n, s;
	while ( cin >> n >> s )
	{
		if ( n == 0 && s == 0 ) break;
		int answer = 0;
		for ( int i = 0; i < 1 << 10; i++ )
		{
			if ( bit_count( i ) == n )
			{
				int sum = 0;
				for ( int j = 0; j < 10; j++ )
				{
					if ( i & 1 << j )
					{
						sum += j;
					}
				}
				if ( sum == s )
				{
					answer++;
				}
			}
		}
		cout << answer << endl;
	}

	return 0;
}

Measured memory_bytes: 0
/*Lucky_Glass*/
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=2e5;
int n;
struct WORK{int tim,ded;}wrk[N+5];
bool cmp(WORK A,WORK B){return A.ded<B.ded;}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d%d",&wrk[i].tim,&wrk[i].ded);
	sort(wrk+1,wrk+1+n,cmp);
	int Tim=0;
	for(int i=1;i<=n;i++){
		Tim+=wrk[i].tim;
		if(Tim>wrk[i].ded){
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	return 0;
}

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

int main() {
    int i,j,k,l,M,N,H,W,a,x,temp ;
    string str,ans;
    cin >> H >> W;
    vector<vector<char>> HW(H,vector<char>(W));
  	vector<vector<int>> out(H,vector<int>(W));
  
    for(i = 0 ; i < H ; i++){
      for(j = 0 ; j < W ; j++){
      	cin >> HW[i][j];
      }
    }
  	ans = "Yes";
  	for(i = 0 ; i < H ; i++){
      for(j = 0 ; j < W ; j++){
      	if (HW[i][j] == '#'){
        	if(i-1 >=0 && HW[i-1][j] == '#'){}
          	else if(j-1 >=0 && HW[i][j-1] == '#'){}
          	else if(i+1 < H && HW[i+1][j] == '#'){}
          	else if(j+1 < W && HW[i][j+1] == '#'){}
          	else{ans = "No";}     
        }
      }
    }
  	cout << ans << endl;
    return 0;
}

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

int main(){
  int n;
  string ans="Yes", a;
    cin >> n;
    if(n%2 == 1)  ans = "No";
    cin >> a;

    for(int i=0; i<n/2; i++)
      if(a[i] != a[n/2+i]) ans = "No";
    cout << ans << endl;

}

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

using namespace std;
#define INF (1<<28)
#define DEKAI 1000000007
#define lp(i,n) for(int i=0;i<n;i++)
#define int long long
signed main(){
  int n;
  cin>>n;
  string s,t;
  cin>>s>>t;
  lp(i,n){
    int stat=0;
    for(int j=i;j<n;j++){
      if(s[j]!=t[j-i]){
        stat=1;
        break;
      }
    }
    if(stat==0){
      cout<<n+i<<endl;
      return 0;
    }
  }
  cout<<n*2<<endl;
  return 0;
}

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

int n,m,k;

struct P{
    int a,b;
    bool operator<(P rhs){
        return a>rhs.a;
    }
};

vector<P> ps;

int calc(vector<P> ptmp){
    sort(ptmp.begin(),ptmp.end());
    int res=0;
    int rest=m;
    for(int i=0;i<k;i++){
        int tmp=min(rest,ptmp[i].b);
        res+=tmp*ptmp[i].a;
        rest-=tmp;
    }
    return res+rest;
}
int dfs(int cnt,int id,vector<P>& ptmp){
    if(cnt==k) return calc(ptmp);
    int res=0;
    for(int i=id+1;i<n;i++){
        ptmp.push_back(ps[i]);
        res=max(res,dfs(cnt+1,i,ptmp));
        ptmp.pop_back();
    }
    return res;
}
int main(){
    cin>>n>>m>>k;
    ps.resize(n);

    for(int i=0;i<n;i++) cin>>ps[i].a;
    for(int i=0;i<n;i++) cin>>ps[i].b;

    vector<P> ptmp;
    cout<<dfs(0,-1,ptmp)<<endl;
    return 0;
}


Measured memory_bytes: 3160
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {
    char a[100100];
	int co=0;
	int i=1,q=0;
	cin>>a; 
	int p=strlen(a);
	for(int j=1;j<p;j++){
		if(a[j]!=a[j-1]){
			co++;
		}
	} 
	cout<<co;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int l;
string q,h,e1,e2,b1,b2;
int cz(string a,string b){
	int j,maxx=-1;
	for(int i=0;i<b.length();i++){
		j=0;
		while(b[i+j]==a[j]){
			j++;
		}
		maxx=max(maxx,j);
	}
	return maxx;
}
int main(){
	cin>>l>>q>>h;
	e1=q;b1=q;
	e2=h;b2=h;
	reverse(e1.begin(),e1.end());
	reverse(q.begin(),q.end());
	for(int i=0;i<q.length();i++){
		if(e1[0]==e2[0]){
			e1.erase(0,1);
			e2.erase(0,1);
			q.erase(0,1);
		}
	}
	if(b2==b1){
		cout<<b1.length()<<endl;
	}
	else{
		if(cz(b2,b1)>0){
			cout<<b1.length()*2-cz(b2,b1)<<endl;
		}
		else{
			cout<<q.length()+h.length()<<endl;
		}	
	}
	//cout<<"cf:"<<cz(b2,b1)<<endl;
	return 0;
}


Measured memory_bytes: 256
a, b, c, d = list(map(int, input().split()))
#a = list(map(int, input().split()))
count = 0
while a > 0 and c > 0:
    if count % 2 == 0:
        c -= b
    else:
        a -= d
    count += 1

if a <= 0:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 9168
import sys

input = sys.stdin.readline


class Solution:
    def main(self):
        L, R = map(int, input().split())

        ans = 2019
        for i in range(L, min(R + 1, L + 2019)):
            for j in range(i + 1, min(R + 1, L + 2019)):
                ans = min(ans, (i * j) % 2019)

        print(ans)


# Run main
if __name__ == '__main__':
    Solution().main()


Measured memory_bytes: 39024
def solve(s)
  changed_points = []

  while true
    i = s.index("apple")
    break if i.nil?
    s[i, 5] = "peach"
    changed_points.push(i)
  end

  i = 0
  while true
    i = s.index("peach", i + 1)
    break if i.nil?
    next if changed_points.include?(i)
    s[i, 5] = "apple"
  end

  s
end

puts solve(gets)

Measured memory_bytes: 6092
n,a,b,c,d = map(int,input().split())
s = input()
if c < d:
    s1 = s[a:c]
    s2 = s[b:d]
    if "##" in s1 or "##" in s2:
        print("No")
    else:
        print("Yes")
else:
    s3 = s[b-2:d+1]
    s4 = s[a:c]
    if "..." in s3:
        if "##" in s4:
            print("No")
        else:
            print("Yes")
    else:
        print("No")

Measured memory_bytes: 3636
def main():

    from collections import Counter
    import sys
    input = sys.stdin.buffer.readline

    N = int(input())
    a = list(map(int, input().split()))

    dp = [[[0]*(N+1) for _ in range(N+1)] for _ in range(N+1)]
    c = Counter(a)

    # メモ化再帰ではpypy3でもTLEするのでforループを使う
    # j==k==0の場合を計算 → k==0の場合を計算 → 一般の場合を計算
    for k in range(c[3]+1):
        for j in range(c[3]+c[2]-k+1):
            for i in range(N-j-k+1):
                if i+j+k == 0:
                    continue
                else:
                    tmp = N
                    if i > 0: # IndexError防止
                        tmp += dp[i-1][j][k]*i
                    if j > 0:
                        tmp += dp[i+1][j-1][k]*j
                    if k > 0:
                        tmp += dp[i][j+1][k-1]*k
                    dp[i][j][k] = tmp/(i+j+k) # 割り算をまとめないとTLE

    print(dp[c[1]][c[2]][c[3]])

if __name__ == '__main__':
    main()

Measured memory_bytes: 599048
/**
*    author:  yuya1234
*    created: 09.07.2020 14:20:24
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define FORV(i,v) for(auto i=v.begin(); i!=v.end();i++)

#define ALL(v) (s).begin(), (s).end()
#define SORT(s) sort((s).begin(),(s).end())
#define SORTD(s) sort((s).rbegin(),(s).rend())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define SZ(x) ((int)(x).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))

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

  int n,k;
  cin>>n>>k;

  int p[n];

  REP(i,n)
  {
    cin>>p[i];
  }

  double ans=0,sum=0;
  REP(i,k)
  {
    sum+=(0.5*p[i]*(1+p[i]))/p[i];
  }
  ans=sum;

  FOR(i,1,n-k)
  {
    sum-=(0.5*p[i-1]*(1+p[i-1]))/p[i-1];
    sum+=(0.5*p[i+k-1]*(1+p[i+k-1]))/p[i+k-1];
    ans=max(ans,sum);
  }

  printf("%.12lf\n",ans);

  return 0;
}

Measured memory_bytes: 4552
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_N = int(3e5 + 5);

bool prime[MAX_N];
vector<int> v;

void solve(int n){
    fill(prime, prime+n+1,true);
    prime[0] = prime[1] = false;
    for(int i=6;i*i<=n;i++){
        if((i%7==1 || i%7==6) && prime[i]){
            for(int j=i*i;j<=n;j+=i){
                prime[j] = false;
            }
        }
    }
    for(int i=0;i<=n;i++){
        if((i%7==1 || i%7==6) && prime[i]){
            v.push_back(i);
        }
    }
}

int main() {
    solve(300000);
    int x;
    while(cin >> x, x!=1){
        cout << x << ":";
        for(auto i : v){
            if(x%i==0) cout << " " << i;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3544
# 1行に複数の数値を入力する場合

a, b = map(int, input().split())
x = 0

if(a >= b):
    x += a
    if((a-1)>=b):
        x += (a-1)
    else:
        x += b
else:
    x += b
    if(a>=(b-1)):
        x += a
    else:
        x += b-1

print(x)


Measured memory_bytes: 2940
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<string.h>

using namespace std;

#define INF 1000000

int E,V,r[50][3],d[12][12];

void warshall_floyd(){
  for(int k=0;k<V;k++)
    for(int i=0;i<V;i++)
      for(int j=0;j<V;j++)
        d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
}

void init(){
  for(int i=0;i<12;i++)
    for(int j=0;j<12;j++)
      d[i][j]=INF;

  memset(r,0,sizeof(r));
  V=0;
  E=0;
}

void solve(){
  warshall_floyd();

  int res[12];
  fill(res,res+12,0);


  for(int i=0;i<V;i++){
    for(int j=0;j<V;j++){
        res[i]+=d[i][j];
    }
  }


  int res1=INF;
  int res2=INF;

  for(int i=0;i<V;i++){
    if(res[i]<res2){
      res1=i;
      res2=res[i];
    }
  }

  printf("%d %d\n",res1,res2);
}

int main(){
  while(true){
    init();
    scanf("%d",&E);
    if(E==0) break;
    for(int i=0;i<E;i++){
      scanf("%d%d%d",&r[i][0],&r[i][1],&r[i][2]);
    }

    for(int i=0;i<10;i++){
      V=max(V,r[i][1]);
    }
    V++;


    for(int i=0;i<E;i++){
      d[r[i][0]][r[i][1]]=r[i][2];
      d[r[i][1]][r[i][0]]=r[i][2];
    }

    for(int i=0;i<V;i++)
      d[i][i]=0;

    solve();
  }
  return 0;
}

Measured memory_bytes: 1188
#include<iostream>
#include<set>
#include<vector>
#include<array>
#include<algorithm>
#include<chrono>

uint64_t xor64(void) {
  static uint64_t x = 88172645463325252ULL;
  x = x ^ (x << 7);
  return x = x ^ (x >> 9);
}

auto b_cl = std::chrono::system_clock::now();
inline double get_time() {
  auto e_cl = std::chrono::system_clock::now();
  double msec = std::chrono::duration_cast<std::chrono::milliseconds>(e_cl - b_cl).count();
  return msec;
}

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int D; std::cin >> D;
  int c[26];
  for(auto& ci: c) std::cin >> ci;
  std::vector<std::array<int,26>> s(D);
  for(int d = 0; d < D; ++d) {
    for(auto& si: s[d]) std::cin >> si;
  }
  std::vector<int> t(D);
  {
    int sum = 0;
    for(int ci: c) sum += ci;
    std::vector<int> sc(26, 0);
    int d = 0;
    for(;;) {
      for(int i = 0; i < 26; ++i) sc[i] += c[i];
      for(int i = 0; i < 26; ++i) if(sc[i] >= sum) {
        if(d < D) { t[d] = i; ++d; }
        sc[i] -= sum;
      }
      if(d >= D) break;
    }
  }
  std::set<int> last[26];
  for(auto& li: last) li.insert(-1); // sentinel
  int ans = 0;
  for(int d = 0; d < D; ++d) {
    int t1 = t[d];
    ans += s[d][t1];
    last[t1].insert(d);
    for(int i = 0; i < 26; ++i) {
      ans -= c[i]*(d - *last[i].rbegin());
    }
  }
  for(auto& li: last) li.insert(D); // sentinel
  
  // additional score when t[d] = i compare to t[d] = -1
  auto sum_up = [](int d) { return d*(d-1)/2; };
  auto score = [&](int d, int i)->int {
    int res = s[d][i];
    auto it = last[i].lower_bound(d);
    int nd = *it;
    int pd = *--it;
    int diff = sum_up(d-pd) + sum_up(nd-d) - sum_up(nd-pd);
    res -= c[i]*diff;
    return res;
  };
  int lm = 0, renew = 0;
  int sc[26];
  auto one_day = [&](int d) {
    int pi = t[d];
    last[pi].erase(d);
    for(int i = 0; i < 26; ++i) sc[i] = score(d, i);
    int mi = std::max_element(sc, sc+26) - sc;
    if(mi != pi) {
      t[d] = mi;
      ans += sc[mi] - sc[pi];
      ++renew;
    }
    last[mi].insert(d);
  };
  
  // hill climbing
  int range = 16;
  for(int rep = 0;; ++rep) {
    if((xor64()>>25)%2) {
      one_day(xor64()%365);
    } else {
      // swap
      int d1 = xor64()%D, d2 = xor64()%D;
      while(d1 < d2-range || d2 < d1-range || t[d1] == t[d2]) {
          d1 = xor64()%D; d2 = xor64()%D;
      }
      int pi1 = t[d1], pi2 = t[d2];
      last[pi1].erase(d1);
      int diff = score(d1, pi2) - score(d1, pi1);
      last[pi2].insert(d1);
      last[pi2].erase(d2);
      diff += score(d2, pi1) - score(d2, pi2);
      if(diff > 0) {
        last[pi1].insert(d2);
        t[d1] = pi2;
        t[d2] = pi1;
        lm = 0;
      } else {
        last[pi2].insert(d2);
        last[pi2].erase(d1);
        last[pi1].insert(d1);
      }
    }
    if(rep%100 == 0) {
      int x = get_time();
      if(x > 1980) break;
      //if(x > 200) range = 25;
      //if(x > 400) range = 20;
      //if(x > 700) range = 15;
      //if(x > 1000) range = 10;
    }
  }
  for(auto ti: t) std::cout << ti+1 << "\n";
  return 0;
}


Measured memory_bytes: 3676
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }
bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }

long mod = 10^^9 + 7;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto A = RD;
	auto B = RD;
	auto C = RD;

	writeln(A == B && B == C ? "Yes" : "No");
	stdout.flush();
	debug readln();
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (N) = readLine()!!.split(" "). map { it.toInt() }
    val X = readLine()!!.split(" "). map { it.toInt() }
    var min = Integer.MAX_VALUE
    for (i in 1 .. 100) {
        var vit = 0
        X.forEach {
            vit += (it - i) * (it - i)
        }
        min = Math.min(min, vit)
    }
    println(min)
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

int main() {
  int N ;cin >> N;
  vector<pair<int, int>> vs;
  rep(i, N) {
    int a, b; cin >> a >> b;
    vs.emplace_back(b, a);
  }
  sort(vs.begin(), vs.end());
  ll sum = 0;
  rep(i, N) {
    sum += vs[i].second;
    if (sum > vs[i].first) {
      cout << "No\n";
      return 0;
    }
  }
  cout << "Yes\n";
}


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

int N, W;
int v, w;
int dp[128][10240] = {0};

int main() {
    cin >> N >> W;

    for (int i=1; i<=N; ++i) {
        cin >> v >> w;
        for (int j=0; j<=W; ++j) {
            if (j >= w) dp[i][j] = max(dp[i-1][j], dp[i][j-w]+v);
            else dp[i][j] = dp[i-1][j];
        }
    }

    cout << dp[N][W] << endl;

    return 0;
}


Measured memory_bytes: 7088
#include <iostream>
//#include <cstring>
//#include <cctype>
//#include <ctime>
using namespace std;


int main(){
    char ch;
    int count[26][1];
    for(int i = 0; i < 26; i++){
        count[i][0] = 0;
    }
    while (cin >> ch) {
        if(ch == EOF)break;
        ch = tolower(ch);
        if(ch >='a' && ch<='z')
            count[ch - 'a'][0]++;
    }
    for(int i = 0; i < 26; i++){
        cout << (char)('a' + i) << " : " << count[i][0] << endl;
    }
    return 0;
}

Measured memory_bytes: 1140
// Package main provides
//
// File:  a.go
// Author: ymiyamoto
//
// Created on Sun Jan  6 00:21:47 2019
//
package main

import "fmt"

func main() {
	var s1, s2 string
	fmt.Scan(&s1, &s2)

	for i := range s1 {
		if s1[i] != s2[len(s2)-1-i] {
			fmt.Println("NO")
			return
		}
	}
	fmt.Println("YES")
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
	int n = 2;
	while(n--){
		int m = 10, s[10];
		while(m--){
			cin >> s[m];
		}
		sort(s, s + 10);
		cout << (s[9] + s[8] + s[7]) << (n == 0 ? "\n" : " ");
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5;
char s[15];
int a[5];
int n;
int main()
{
    scanf("%d",&n);
    while(n--)
    {
        scanf("%s",s);
        if(s[0]=='M') ++a[0];
        if(s[0]=='A') ++a[1];
        if(s[0]=='R') ++a[2];
        if(s[0]=='C') ++a[3];
        if(s[0]=='H') ++a[4];
    }
    long long ans=0;
    for(int i=0;i<5;++i)
        for(int j=i+1;j<5;++j)
            for(int k=j+1;k<5;++k)
                ans+=1LL*a[i]*a[j]*a[k];
    printf("%lld\n",ans);
}


Measured memory_bytes: 256
n,a,b,c,d = map(int, input().split())
s = str(input())
e = 0
if c>d:
    e+=1
for i in range(a-1, max(c,d)-1):
    if s[i]==s[i+1] and s[i]=="#":
        print("No")
        exit()
    
    if e:
        if i>=b-1 and i<d and s[i-1]==s[i]==s[i+1]:
            e = 0
if e==0:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3572
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	max, sum := 0, 0
	for i := 0; i < n; i++ {
		var t int
		fmt.Scan(&t)
		if max < t {
			max = t
		}
		sum += t
	}
	fmt.Print(sum - (max / 2))
}


Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <math.h>
#include <climits>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <map> 
#include <set>
#include <string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
const ll MD = 1000000007;

/* sample input

*/

int main()
{
	ll n;
	ll *A;
	ll odd = 0 , guu = 0;
	ll answer = 1;
	cin >> n;
	
	A = new ll[n];
	
	for (ll i = 0; i < n; i++) {
		cin >> A[i];
		if (A[i] % 2 == 0) {
			guu++;
		}
		else {
			odd++;
		}
		answer *= 3;
	}
	ll sub = 1;
	for (ll i = 0; i < guu; i++) {
		sub *= 2;
	}

	answer = answer - sub;

	cout << answer;

	return 0;
}

Measured memory_bytes: 256
abc=list("abcdefghijklmnopqrstuvwxyz")

class SegmentTree:
    def __init__(self, init_value: list, segfunc, ide_ele):
        n = len(init_value)
        self.N0 = 1 << (n - 1).bit_length()
        self.ide_ele = ide_ele
        self.data = [ide_ele] * (2 * self.N0)
        self.segfunc = segfunc
        
        for i, x in enumerate(init_value):
            self.data[i + self.N0 - 1] = x
        for i in range(self.N0 - 2, -1, -1):
            self.data[i] = self.segfunc(self.data[2 * i + 1], self.data[2 * i + 2])
    
    def update(self, k: int, x):
        k += self.N0 - 1
        ############################
        self.data[k] = x
        ###########################
        while k:
            k = (k - 1) // 2
            self.data[k] = self.segfunc(self.data[k * 2 + 1], self.data[k * 2 + 2])
    
    def query(self, left: int, right: int):
        L = left + self.N0
        R = right + self.N0
        res = self.ide_ele
        ##########################
        a, b = [], []
        while L < R:
            if L & 1:
                a.append(L - 1)
                L += 1
            if R & 1:
                R -= 1
                b.append(R - 1)
            L >>= 1
            R >>= 1
        for i in a + b[::-1]:
            res = self.segfunc(res, self.data[i])
        ##########################
        return res



idx={}
for i in range(len(abc)):
    idx[abc[i]]=i
#print(idx)
N=int(input())
S=list(input())
Q=int(input())
L=[[0]*(N+1) for _ in range(26)]

def add(a,b):
    return a+b


for i in range(N):
    s=S[i]
    L[idx[s]][i+1]=1
    

segdict={}
for i in range(26):
    segdict[i]=SegmentTree(L[i],add,0)

for i in range(Q):
    query=input().split()
    num=int(query[0])

    if num==1:
        i=int(query[1])
        c=query[2]
        nows=S[i-1]
        segdict[idx[nows]].update(i,0)
        segdict[idx[c]].update(i,1)
        S[i-1]=c
    else:
        l=int(query[1])
        r=int(query[2])
        sub=0
        for j in range(26):
            x=segdict[j].query(l,r+1)
            if x>0:
                sub+=1
        print(sub)

Measured memory_bytes: 419536
// B - Unhappy Hacking (ABC Edit)
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
#define int long long
#define MOD 1000000007
typedef vector<int> vi;
typedef pair<int,int> pi;
#define inf 1e18
#define For(i,a,b) for (int i = a; i < b; i++)
#define Rep(i,a,b) for (int i = a; i <= b; i++)
#define ps(x,y) fixed << setprecision(y) << x 
#define pb push_back 
#define mp make_pair 
 
int32_t main()
{
    fast;
    string s, ans; cin >> s;
    For(i, 0, s.size()) {
        if(s[i] == 'B') {
            if(ans.size() > 0) ans.pop_back();
        }
        else ans += s[i];
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pii pair<int,int>
const long long MOD=1000000007;

int main(){
    int a,b,k;
    cin>>a>>b>>k;
    for(int i=100;i>0;--i){
        if(a%i==0 && b%i==0) k--;
        if(k==0){
            cout<<i<<endl;
            break;
        }
    }
    return 0;
}

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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9+7;
const ll INF = 1e9+5;
const int MAXN = 500005;

int n, k;
double a[200005];

int main() {
	cin >>n>>k;
	for (int i=0 ; i<n ; i++) {
		int x;
		scanf("%d", &x);
		a[i] = double(x+1)/2;
	}
	double exp = 0;
	double maxx = 0;
	for (int i=0 ; i<k ; i++) {
		exp += a[i];
	}
	maxx = exp;
	for (int i=k ; i<n ; i++) {
		exp-=a[i-k];
		exp+=a[i];
		maxx = max(maxx, exp);
	}
	printf("%.7lf\n", maxx);
	return 0;
}

Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();
		long N =  Long.parseLong(W.split(" ")[0]);
		long X =  Long.parseLong(W.split(" ")[1]);

		String[] Wi = in.readLine().split(" ");
		int n =1;
		long p=0;

		for(int i = 0;i<Wi.length;i++){
			p+=Integer.parseInt(Wi[i]);
			if(p <= X){
				n++;
			}
		}

		System.out.println(n);

	}
}


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

int main()
{
    int N;
    string S;

    cin >> N;
    cin >> S;
    int res = 0;

    for (int i = 0; i < N-2; i++)
    {
        if (S.substr(i, 3) == "ABC")
        {
            res++;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import deque
H, W, M = map(int, input().split())
bomb = []
counth = [0 for k in range(H)]
countw = [0 for k in range(W)]
for k in range(M):
  h, w = map(int, input().split())
  h -= 1
  w -= 1
  bomb.append(h+ w*H)
  counth[h] += 1 
  countw[w] += 1
counth = deque(counth)
countw = deque(countw)

def binary_search(list, item):
    low = 0
    high = len(list) - 1

    while low <= high:
        mid = (low + high) //2
        guess = list[mid]
        if guess == item:
            #return mid
            return True
        if guess > item:
            high = mid -1
        else:
            low = mid + 1

    #return None
    return False


maxh = max(counth)
maxw = max(countw)
index_h = deque([])
index_w = []
for k in range(H):
  h = counth.popleft()
  if h == maxh:
    index_h.append(k)

for k in range(W):
  w = countw.popleft()
  if w == maxw:
    index_w.append(k)

ans = maxh + maxw - 1
lenh = len(index_h)
lenw = len(index_w)


if lenh*lenw > M:
  ans += 1
else:
  bomb.sort()
  kouho = []
  for i in range(lenh):
    h = index_h.pop()
    for j in range(lenw):
      w = index_w[j]
      kouho.append(h+ H*w)
  for K in kouho:
    if binary_search(bomb, K):
      continue
    else:
      ans += 1
      break
    
print(ans)




Measured memory_bytes: 147536
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    int max = -INF, max2 = -INF;
    REP(i, N)
    {
        cin >> A[i];
        if (A[i] > max)
        {
            max2 = max;
            max = A[i];
        }
        else if (A[i] >= max2)
        {
            max2 = A[i];
        }
    }

    REP(i, N)
    {
        if (A[i] == max)
        {
            cout << max2 << endl;
        }
        else
        {
            cout << max << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 2432