akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
#define endl '\n'
#define mod 998244353
#define pi 3.14159265358979323846
#define rep(i,a,b) for(int i=a;i<b;i++)
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define inf INT_MAX
#define maxx 2*100000 + 5

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

    int n, b, c;
    cin >> n >> b >> c;

    vi dp(n+1);

    rep(i,1,n+1)
    {
        rep(j,i+1,n+1)
        {
            int p = j - i;
            int k = abs(i-b) + abs(j-c) + 1;
            dp[min(p,k)]++;
        }
    }

    rep(i,1,n) cout << dp[i] << endl;


    return 0;
}

 

Measured memory_bytes: 256
def bsort (a,n)
  for i in 0...n
    j = n-1
    while j > i
      if a[j][1].ord < a[j-1][1].ord
        t = a[j]
        a[j] = a[j-1]
        a[j-1] = t
      end
      j -= 1
    end
  end
  a
end

def ssort (a,n)
  for i in 0...n
    min = i
    for j in i...n
      min = j if a[j][1].ord < a[min][1].ord
    end
    if min != i
      t = a[i]
      a[i] = a[min]
      a[min] = t
    end
  end
  a
end

n = gets.to_i
a = gets.split
b = bsort(a.clone, n)
c = ssort(a.clone, n)

puts b.join(" ")
puts "Stable"

puts c.join(" ")
if b == c
  puts "Stable"
else
  puts "Not stable"
end



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

const int N = 500054, BASE = 100000000;

int n;
int s[N], f[10000];
char str[N];

inline int digit_sum(int x) {return f[x / 10000] + f[x % 10000];}

int main() {
	int i, L, cur = 0, dsum = 0, ans;
	char tok[9]; tok[8] = 0;
	for (i = 1; i < 10000; ++i) f[i] = f[i / 10] + i % 10;
	scanf("%s", str), L = strlen(str);
	for (i = 1; i * 8 <= L; ++i)
		memcpy(tok, str + (L - i * 8), 8), s[n++] = strtol(tok, NULL, 10);
	if (L & 7)
		memcpy(tok, str, L & 7), tok[L & 7] = 0, s[n++] = strtol(tok, NULL, 10);
	for (i = 0; i < n + 2; ++i)
		cur = s[i] * 9 + cur, s[i] = cur % BASE, cur /= BASE, dsum += digit_sum(s[i]);
	for (ans = 1; ; ++ans) {
		dsum -= digit_sum(*s), *s += 9;
		for (i = 0; s[i] >= BASE; ++i)
			dsum += digit_sum(s[i] -= BASE) - digit_sum(s[i + 1]++);
		dsum += digit_sum(s[i]);
		if (dsum <= 9 * ans) return printf("%d\n", ans), 0;
	}
	return -1;
}

Measured memory_bytes: 1024
S = input()
answer = [0] * (len(S) + 1)

for i in reversed(range(len(S))):
    if S[i] == 'W':
        answer[i] = answer[i + 1] + 1
    else:
        answer[i] = answer[i + 1]

cnt = 0
for i in range(len(answer) - 1):
    if answer[i] == answer[i + 1]:
        cnt += answer[i]

print(cnt)

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

#define int long long

signed main() 
{ 
	int n,d;
	cin>>n>>d;
	int ans = 0;
	for(int i=0;i<n;i++){
		int x,y;
		cin>>x>>y;
		if(x*x+y*y<=d*d)
		ans++;
	}
	cout<<ans;
	
} 


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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define endl        "\n"
#define repp(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) 	for(int i=a;i<=b;i++)
#define IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int N=1e5 + 5;

int32_t main()
{
	IOS;
	//memset(dp,-1,sizeof(dp));
	int n;
	cin >> n;
	vii v;
	rep(i,1,n)
	{
		int x;
		cin >> x;
		v.pb({x,i});	
	}	
	sort(all(v));
	for(auto it: v)
	{
		cout << it.second << " ";
	}
}


Measured memory_bytes: 2544
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define _GLIBCXX_DEBUG

signed main() {
  int N, M; cin >> N >> M;
  vector<tuple<int,int,int>> C(M);
  rep(i, 0, M) {
    int p, y; cin >> p >> y;
    C[i] = make_tuple(p, y, i);
  }
  
  sort(all(C));
  vector<pair<int,string>> P(0);
  int x = 1;
  rep(i, 0, M) {
    if(get<0>(C[i]) == get<0>(C[i-1]) && i > 0) x++;
    else x = 1;
    string s = "";
    string pp = to_string(get<0>(C[i]));
    string xx = to_string(x);
    int k = 6-pp.size();
    rep(i, 0, k) s += '0';
    s += pp;
    k = 6-xx.size();
    rep(i, 0, k) s += '0';
    s += xx;
    P.push_back(make_pair(get<2>(C[i]), s));
  }
  sort(all(P));
  rep(i, 0, M) cout << P[i].second << endl;
  
}

Measured memory_bytes: 11632
//
//  Created by TaoSama on 2015-12-04
//  Copyright (c) 2015 TaoSama. All rights reserved.
//
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>

using namespace std;
#define pr(x) cout << #x << " = " << x << "  "
#define prln(x) cout << #x << " = " << x << endl
const int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;

int n, m;
int a[20], b[20];

int get() {
    if(accumulate(a + 1, a + 1 + n, 0) != accumulate(b + 1, b + 1 + n, 0))
        return INF;
    int t[20]; memcpy(t, b, sizeof b);
    int ret = 0;
    for(int i = 1; i <= n; ++i) {
        if(a[i] == t[i]) continue;
        for(int j = i + 1; j <= n; ++j) {
            if(t[j] == a[i]) {
                while(j > i) {
                    swap(t[j], t[j - 1]);
                    --j; ++ret;
                }
                break;
            }
        }
    }
    return ret;
}

int calc() {
    int ans1 = get();
    for(int i = 1; i <= n; ++i) b[i] ^= 1;
    int ans2 = get();
    return min(ans1, ans2);
}

int main() {
#ifdef LOCAL
    freopen("C:\\Users\\TaoSama\\Desktop\\in.txt", "r", stdin);
//  freopen("C:\\Users\\TaoSama\\Desktop\\out.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(0);

    while(scanf("%d%d", &n, &m) == 2) {
        for(int i = 1; i <= n; ++i) scanf("%d", a + i);
        int idx = 1, v = 1;
        while(m--) {
            int x; scanf("%d", &x);
            while(x--) b[idx++] = v;
            v ^= 1;
        }
        printf("%d\n", calc());
    }
    return 0;
}

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


#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, deque<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; }



int main() {
    int N; 
    long long K;
    cin >> N >> K;
    vector<int> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i], --A[i];

    deque<int> a; // 繰り返しの部分
    vector<bool> seen(N, false); // 一度見たかどうか
    int cur = 0;
    while (true) {
        // 一度通った頂点を見つけたときの処理
        if (seen[cur]) {
            while (a[0] != cur) {
                // 最初の余計な数手分を除去する
                --K;
                a.pop_front();

                // 繰り返す前に K が限界になったらリターン
                if (K == 0) {
                    cout << a[0]+1 << endl;
                    return 0;
                }
            }
            break;
        }
        // 最初は愚直にシミュレーションしつつ、履歴をメモしていく
        a.push_back(cur);
        seen[cur] = true;
        cur = A[cur];
    }
    cout << a[K % a.size()]+1 << endl;
}

Measured memory_bytes: 4824
N,M,V,P = map(int,input().split())
A = list(map(int,input().split()))

#二分探索するからAをsortする
A = sorted(A,reverse=True)

left=0
right=N-1

while left<=right:
    mid = (left+right)//2

    if mid<P:#そもそも入っている
        left = mid + 1
    elif A[mid] + M < A[P-1]:
        right = mid -1
    else:
        voted = P * M
        for _ in range(mid+1,N):
            voted += M

        for v in A[P-1:mid]:
            voted += A[mid]+M-v

        if voted >= M*V:
            left= mid+1
        else:
            right = mid-1

print(left)


Measured memory_bytes: 14480
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) {
    new Main().run();
  }

  public void run() {

    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      String t = br.readLine();
      String p = br.readLine();

      StringBuilder buf = new StringBuilder();
      int max = t.length() - p.length();
      int pos = 0;
      for (int i = 0; i <= max; i=pos+1) {
        pos = t.indexOf(p, i);
        if(pos == -1) break;
        buf.append(pos).append("\n");
      }
      
      System.out.print(buf);
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
}


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

int gcd(int a, int b)
{
    int c;

    if (a < b) {
        a+=b; b=a-b; a-=b;
    }

    while (b != 0) {
        c = a % b;
        a = b;
        b = c;
    }

    return a;
}

int main(void){
    string str;
    cin >> str;
    int stringSize = str.size(), ans = 0;
    for(int i = 0; i < stringSize; i++){
        if(i % 2 == 0 && str[i] == '0') ans++;
        else if(i % 2 != 0 && str[i] == '1') ans++; 
    }
    if(ans > stringSize - ans) ans = stringSize - ans;
    cout << ans << endl;


}

Measured memory_bytes: 512
import sys
import math
from fractions import gcd
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def main():
    N = NI()
    A = NLI()
    LA = [1] * N
    RA = [1] * N
    for i in range(N):
        if i == 0:
            LA[0] = A[0]
            RA[N-1] = A[N-1]
            continue
        LA[i] = gcd(LA[i-1], A[i])
        RA[N-i-1] = gcd(RA[N-i], A[N-i-1])
    ans = 0
    for i in range(N):
        if i == 0:
            ans = RA[1]
            continue
        if i == N-1:
            ans = max(ans, LA[N-2])
            continue
        ans = max(ans, gcd(LA[i-1], RA[i+1]))
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 16148
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#include <vector>
#include <string>
#include<iomanip>//浮動小数点数を出力する制度の指定
//使い方　数値をnumとして　cout<<setprecision(n)<<num ;nは桁数
#define rep(i,n) for(int i = 0; i < (n);i++)
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
using namespace std;
using ll =long long;
using db = double;
#define INF 2000000000
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
/*覚えてないことメaモ
  数値型から文字列に変換　to_string(number);これは簡単
  文字列から数値型に変換　stoi(number)
  文字列からllに変換　stoll(number)
  __gcd(a,b)は最大公約数を取ってくれる、aとb
  の大きい方をNとしたとき、計算量は√N
 */
const int mod = 1e9 + 7;
//ここから書き始める
int main(){
	ll n ;
	cin >> n; 
	ll ans =  1;
	for(int i = 1 ; i < n + 1 ; i ++){
		ans *= i;
		ans %= mod;
	}
	cout<<ans<<endl;
		

}



Measured memory_bytes: 256
n,m = gets.chomp.split(" ").map(&:to_i)
a = gets.chomp.split(" ").map(&:to_i)

sum = a.inject(:+)

thr = (sum/(4.0*m)).ceil

a.sort.reverse_each { |e|
  if e < thr
    break
  else
    m -= 1
    if m == 0
      break
    end
  end
}
if m == 0
  puts("Yes")
else
  puts("No")
end

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

int main()
{
	long long n, a, mini = 1000000000, maxi = -1000000000, sum = 0;
	cin >> n;
	while (n--) {
		cin >> a;
		mini = min(mini, a);
		maxi = max(maxi, a);
		sum += a;
	}
	cout << mini << ' ' << maxi << ' ' << sum << endl;
	return 0;
}

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<algorithm>
#include<functional>
#include<deque>
#include<string.h>
#include<ctype.h>
using namespace std;


long long sum_array(int v[], int a, int b){
  long long tmp = 0;
  for (int i = a; i <= b; i++){
    tmp += v[i];
  }
  return tmp;
}


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

  sort(a, a+n);

  int min = a[0];
  int max = a[n-1];
  long long sum = sum_array(a, 0, n-1);

  printf("%d %d %lld\n", min, max, sum);
  return 0;
}



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

using namespace std;

template<class T, class U>
void ckmin(T &a, U b)
{
	if (a > b) a = b;
}
template<class T, class U>
void ckmax(T &a, U b)
{
	if (a < b) a = b;
}

#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
#define SZ(x) ((int) ((x).size()))
#define ALL(x) (x).begin(), (x).end()
#define INF 1000000007
#define LLINF 2696969696969696969ll
#define MAXN 100013

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

int N, K;
int arr[MAXN];
int dp[MAXN];

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> N >> K;
	FOR(i, 0, N)
	{
		cin >> arr[i];
		dp[i] = INF;
	}
	dp[0] = 0;
	FOR(i, 0, N)
	{
		FOR(j, 1, K + 1)
		{
			if (i + j > N) break;
			ckmin(dp[i + j], dp[i] + abs(arr[i] - arr[i + j]));
		}
	}
	cout << dp[N - 1] << '\n';
	return 0;
}


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

typedef long long ll;
typedef long double ld;

#define imx INT_MAX
#define imn INT_MIN
#define llmx LLONG_MAX
#define llmn LLONG_MIN

#define fi first
#define se second
#define pb push_back



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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, k, c;
	cin>>n>>k>>c;
	string s;
	cin>>s;
	vector<int> L(k), R(k);
	int i = 0, count=0;
	while(i<n and count<k)
	{
		if(s[i]=='o')
		{
			L[count]=i;
			count++;
			i+=c+1;
		}
		else i++;
	}
	count=k-1, i=n-1;
	while(i>=0 and count>=0)
	{
		if(s[i]=='o')
		{
			R[count]=i;
			count--;
			i-=c+1;
		}
		else i--;
	}
	for(int i = 0; i < k; i++)
	{
		if(L[i]==R[i])
		{
			cout<<L[i]+1<<endl;
		}
	}
}

Measured memory_bytes: 3348
#include <iostream>
#include <ios>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <functional>
#include <cassert>

using namespace std;

using i64 = long long;
using P = pair<i64, i64>;

const i64 mod = 1e9 + 7;

// dp1[i][j] := i 番目まで並べて最後の数がjになるような場合の数
// dp2[i][j] := i 番目まで並べてi + 1 番目に j 以下の数がおけるような場合の数

int main(){
    i64 n, k;
    cin >> n >> k;
    i64 m = 0;
    for(int i = 1; i * i <= n; ++i) m = i;
    vector<vector<i64>> dp1(k, vector<i64>(m + 1)), dp2(k, vector<i64>(m + 1));
    for(int i = 1; i <= m; ++i){
        dp1[0][i] = 1;
        if(n / i == i) dp2[0][i] = 0;
        else dp2[0][i] = n / i - n / (i + 1);
    }
    for(int i = 1; i < k; ++i){
        i64 s = 0;
        for(int j = 1; j <= m; ++j){
            s = (s + dp1[i - 1][j]) % mod;
            if(j * j != n) dp2[i][j] = s * dp2[0][j] % mod;
            else dp2[i][j] = 0;
        }
        for(int j = m; j >= 1; --j){
            s = (s + dp2[i - 1][j]) % mod;
            dp1[i][j] = s;
        }
    }
    i64 ans = 0;
    for(int i = 1; i <= m; ++i) ans = (ans + dp1[k - 1][i]) % mod;
    for(int i = 1; i <= m; ++i) ans = (ans + dp2[k - 1][i]) % mod;
    //for(int i = 1; i <= m; ++i) cout << "dp1[k - 1][" << i << "]: " << dp1[k - 1][i] << endl;
    //for(int i = 1; i <= m; ++i) cout << "dp2[k - 1][" << i << "]: " << dp2[k - 1][i] << endl;
    cout << ans << endl;
}


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

vector<int> l(26, 0);
int last(int d, int i) { return l.at(i); }

int score(int d, int t, vector<int> &c, vector<vector<int>> &s) {
    int res = s.at(d).at(t);
    // l.at(t) = d;
    for(int i = 0; i < 26; i++) {
        if(i != t) {
            res -= c.at(i) * (d - last(d, i));
        }
    }
    return res;
}

int main() {
    int D;
    cin >> D;
    vector<int> c(26);
    vector<vector<int>> s(D + 1, vector<int>(26));

    for(int i = 0; i < 26; i++) {
        cin >> c.at(i);
    }
    for(int d = 1; d <= D; d++) {
        for(int i = 0; i < 26; i++) {
            cin >> s.at(d).at(i);
        }
    }

    int v = 0;
    for(int d = 1; d <= D; d++) {
        int max_score = -9999999;
        int max_t = -1;
        for(int i = 0; i < 26; i++) {
            int is = score(d, i, c, s);
            if(max_score < is) {
                max_score = is;
                max_t = i;
            }
        }
        v += max_score;
        l.at(max_t) = d;
        cout << (max_t + 1) << endl;
    }

    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
typedef long long ll;

struct per{
	int x,y;
};

bool cmp( per p1 , per p2 ){
	if( p1.x==p2.x )return p1.y<p2.y;
	return p1.x>p2.x;
}

int n,i,cur,mind;
ll isp[100123];
per par[100123];
 
int main(){
	
	scanf("%d",&n);
	
	for(i=1;i<=n;i++){
		scanf("%d",&par[i].x);
		par[i].y=i;
	}
	
	sort( par+1 , par+1+n , cmp );
	
	mind=par[1].y;
	cur=par[1].x;
	
	for(i=1;i<=n+1;i++){
		if( cur!=par[i].x ){
			int nekst=par[i].x;
			ll raz=(ll)((ll)cur-nekst)*((ll)i-1);
			isp[mind]+=raz;
			cur=nekst;
		}
		mind=min( mind , par[i].y );
	}
	
	for(i=1;i<=n;i++)printf("%lld\n",isp[i]);
	return 0;
}


Measured memory_bytes: 2688
#include <iostream>
#include <vector>
#include <algorithm>
int k, n;
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cin >> k;
    if (k == 1) {
        std::cout << 1 << "\n";
        std::cout << 1 << "\n";
        return 0;
    }
    int n = 2 * ((k + 3) / 4);
    std::cout << n << "\n";
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            int c = (i + j) % n + (i % 2 == 0 ? 0 : n);
            if (c >= k)
                c -= n;
            std::cout << c + 1 << " \n"[j == n - 1];
        }
    }
    return 0;
}

Measured memory_bytes: 1152
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N;
	while(cin>>N) {
		VI A(N);
		REP(i, N) cin>>A[i];
		VI a(A);
		sort(ALLR(a));
		REP(i, N) {
			ll ans = A[i]==a[0] ? a[1] : a[0];
			cout<<ans<<endl;
		}
	}
	
	return 0;
}


Measured memory_bytes: 4736
// template version 1.12
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

// varibable settings
#define infile "../test/sample-1.in"
#define int long long //{{{
const int INF=1e18;
const int MOD=1e9+7; //}}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

int solve(){
  string s;cin>>s;
  int n = sz(s);

  vi dp1(n, -INF);
  vi dp2(n, -INF);
  dp1[0] = 1;
  dp2[1] = 1;

  rep(i, 0, n){
     if (i+1<n){
       if (s[i+1]!=s[i]) chmax(dp1[i+1], dp1[i]+1);
       chmax(dp1[i+1], dp2[i]+1);
     }

     if (i+2<n){
       chmax(dp2[i+2], dp1[i]+1);
       if (s[i-1]!=s[i+1] || s[i]!=s[i+2]) chmax(dp2[i+2], dp2[i]+1);
     }
  }
  dump(dp1);
  dump(dp2);

  cout << max(dp1[n-1], dp2[n-1]) << endl;

  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 3732
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, l, r) for (ll i = (ll)l; i < (ll)(r); i++)
#define INF 1000000000000000000
#define MAX 200001
#define MOD 1000000007

template <typename T > inline string toString(const T &a) {ostringstream oss; oss << a; return oss.str();};

int main(){
    int N;
    ll ans = 0; 
    cin >> N;
    vector<ll> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    for(int i = 1; i < N; i++){
        ll mae = A[i - 1];
        ll ato = A[i];
        if(mae % 2 == 0) ans += mae / 2;
        else{
            if(ato > 0){
                A[i]--;
                ans += mae / 2 + 1;
            }
            else{
                ans += mae / 2;
            }
        }
    }
    ans += A[N - 1] / 2;
    cout << ans << endl;
}

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

int main()
{
   char s[100];
    gets(s);
   int i,len,x=0,y=0,z=0;
   len=strlen(s);
   for(i=0;i<len;i++){
    if(s[i]!=s[len-i-1]){
        x=1;
        break;
    }
   }
  for(i=0;i<(len-1)/2;i++){
        if(s[i]!=s[(len-1)/2-i-1]){
        y=1;
        break;
    }

   }
  for(i=len/2+1;i<len;i++){
      if(s[i]!=s[len-i+(len/2)]){
        z=1;
        break;
    }

   }
if(x==0 && y==0 && z==0){
    printf("Yes");
}
else{printf("No");}
}


Measured memory_bytes: 1644
#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long
int main(){
  IOS
  ll n,p;
  cin>>n>>p;
  ll c=0;
  while(p%2==0){
   c++;
   p/=2;
}
  c/=n;
  ll ans=pow(2,c);
  for(ll i=3;i<=sqrt(p);i+=2){
   ll c=0;
   while(p%i==0){
   p/=i;
   c++;
}
  c/=n;
  ans=ans*pow(i,c);
}
  if(p>2){
   if(n==1){ ans*=p;}
}
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    a_s = list(map(int,input().split()))
    answer = "APPROVED"
    for a in a_s:
        if (a % 2 == 0)  and (a%3 != 0 and a%5 != 0):
            answer = "DENIED"
    print(answer)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
N = int(input())
sum = 0

for i in range(1,N+1):
    if i % 15 == 0:
        sum += 0
    elif i % 3 == 0:
        sum += 0
    elif i % 5 == 0:
        sum += 0
    else:
        sum += i

print(sum)


Measured memory_bytes: 9100
#include<bits/stdc++.h>
#define ChenChuLing main
using namespace std;
char s[5004];
int k,l;
set<string>tr;
int ChenChuLing (){
    scanf("%s",s+1);
    l=strlen(s+1);
    int cnt=0;
    scanf("%d",&k);
    for(int i=1;i<=5;i++){
        for(int j=1;j+i-1<=l;j++){
            string m="";
            for(int t=j;t<=j+i-1;t++){
                m=m+s[t];
            }
            tr.insert(m);
        }
    }
    string s;
    for(set<string>::iterator it=tr.begin();it!=tr.end()&&k>0;it++,k--){
        s=(*it);
    }
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 1664
N = input()
N = int(N)
A = [int(x) for x in input().split()]
a = 1
if A.count(0) > 0:
    print(0)
    a = 0
else:
    for i in range(N):
        a = a * A[i]
        if a > 10**18:
            a = -1
            print(a)
            break

if a > 0:
    print(a)

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int A[5050];
vector<int> E[5050];
ll dp[5060][5060][2];
int C[5050];
ll to[5053][2];

void dfs(int cur,int pre) {
	C[cur]=1;
	if(A[cur]>0) {
		dp[cur][0][1]=A[cur];
	}
	else {
		dp[cur][0][0]=A[cur];
	}
	FORR(e,E[cur]) if(e!=pre) {
		dfs(e,cur);
		
		int x,y;
		FOR(x,5050) to[x][0]=to[x][1]=1LL<<60;
		for(x=0;x<=C[cur]-1;x++) {
			for(y=0;y<=C[e]-1;y++) {
				
				if(dp[e][y][0]<0 || dp[e][y][1]<1LL<<60) {
					to[x+y+1][0]=min(to[x+y+1][0],dp[cur][x][0]);
					to[x+y+1][1]=min(to[x+y+1][1],dp[cur][x][1]);
				}
				to[x+y][1]=min(to[x+y][1],dp[cur][x][1]+dp[e][y][1]);
				to[x+y][0]=min(to[x+y][0],dp[cur][x][0]+dp[e][y][1]);
				to[x+y][0]=min(to[x+y][0],dp[cur][x][1]+dp[e][y][0]);
				to[x+y][0]=min(to[x+y][0],dp[cur][x][0]+dp[e][y][0]);
			}
		}
		FOR(x,5050) {
			dp[cur][x][0]=to[x][0];
			dp[cur][x][1]=to[x][1];
		}
		C[cur]+=C[e];
	}
	
	
}


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) cin>>A[i];
	FOR(x,5050) FOR(y,5050) dp[x][y][0]=dp[x][y][1]=1LL<<60;
	
	FOR(i,N-1) {
		cin>>x>>y;
		E[x-1].push_back(y-1);
		E[y-1].push_back(x-1);
	}
	
	dfs(0,-1);
	for(i=0;i<=5050;i++) {
		if(dp[0][i][0]<0) return _P("%d\n",i);
		if(dp[0][i][1]<1LL<<60) return _P("%d\n",i);
	}
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 400512
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int sum = sc.nextInt();
		int h = sum/3600;
		int m = (sum%3600)/60;
		int s = ((sum%3600)%60);
		System.out.println(h+":"+m+":"+s);
	}
}


Measured memory_bytes: 26332
import re
PIZ=re.split('[ ]', input())
A=int(PIZ[0])
B=int(PIZ[1])
C=int(PIZ[2])
X=int(PIZ[3])
Y=int(PIZ[4])
a=0
b=0
c=0
if(A+B>=C*2):
    if X<=Y:
        for i in range(X):
            X-=1
            Y-=1
            c+=2
    else:
        for i in range(Y):
            X-=1
            Y-=1
            c+=2
    if A<C*2:
        a+=X
    else:
        c+=X*2
    if B<C*2:
        b+=Y
    else:
        c+=Y*2
else:
    for j in range(X):
        X-=1
        a+=1
    for k in range(Y):
        Y-=1
        b+=1
print(A*a+B*b+C*c)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int K, A, B;
    cin >> K;
    cin >> A >> B;

    int min = A / K;
    int max = B / K;

    for(int i=min; i<=max; i++){
        if(A<=(K*i) and (K*i)<=B){
            cout << "OK" << endl;
            return 0;
        }
    }

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


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <queue>
#define INF 1e+9
using namespace std;

int main(){
	int n,m,q,u[200000],v[200000],qs[200000],d[100000];
	vector<int> G[100000],g[100000];
	vector<int> cnt;
	bool connect[100000] = {},used[200000] = {};
	cin >> n >> m >> q;
	connect[0] = true;
	for(int i = 0;i < n;i++) d[i] = INF;
	for(int i = 0;i < m;i++) {
		cin >> u[i] >> v[i];
		u[i]--;
		v[i]--;
		g[v[i]].push_back(u[i]);
		g[u[i]].push_back(v[i]);
	}
	queue<int> que;
	que.push(0);
	d[0] = 0;
	for(int j = 0;;j++){
		int siz = que.size();
		if(siz == 0) break;
		for(int k = 0;k < siz;k++){
			int V = que.front();que.pop();
			for(int i = 0;i < g[V].size();i++){
				if(d[g[V][i]] > j + 1){
					d[g[V][i]] = j + 1;
					que.push(g[V][i]);
				}
			}
		}
	}
	for(int i = 0;i < q;i++) {
		cin >> qs[i];
		qs[i]--;
		used[qs[i]] = true;
	}
	for(int i = 0;i < m;i++){
		if(!used[i]){
			G[u[i]].push_back(v[i]);
			G[v[i]].push_back(u[i]);
		}
	}
	int res = n - 1;
	que.push(0);
	for(int j = 0;;j++){
		int siz = que.size();
		if(siz == 0) break;
		for(int k = 0;k < siz;k++){
			int V = que.front();que.pop();
			for(int i = 0;i < G[V].size();i++){
				if(!connect[G[V][i]] && d[G[V][i]] == j + 1){
					connect[G[V][i]] = true;
					que.push(G[V][i]);
					res--;
				}
			}
		}
	}
	cnt.push_back(res);
	for(int i = q - 1;i >= 1;i--){
		int tu = u[qs[i]],tv = v[qs[i]];
		G[tu].push_back(tv);
		G[tv].push_back(tu);
		if(connect[tu] && connect[tv]){
			cnt.push_back(res);
			continue;
		}
		if(connect[tv]){
			int t = tu;
			tu = tv;
			tv = t;
		}
		if(!connect[tu] || d[tv] < d[tu] + 1){
			cnt.push_back(res);
			continue;
		}
		connect[tv] = true;
		que.push(tv);
		res--;
		for(int k = 0;;k++){
			int siz = que.size();
			if(siz == 0) break;
			for(int l = 0;l < siz;l++){
				int V = que.front();que.pop();
				for(int j = 0;j < G[V].size();j++){
					if(!connect[G[V][j]] && d[G[V][j]] == d[tu] + k + 2){
						connect[G[V][j]] = true;
						que.push(G[V][j]);
						res--;
					}
				}
			}
		}
		cnt.push_back(res);
	}
	for(int i = q - 1;i >= 0;i--) cout << cnt[i] << endl;
	return 0;
}

Measured memory_bytes: 19244
#include<bits/stdc++.h>
#define  lowbit(x) (x&(-x))
#define  ll long long
#define  ull unsigned long long
#define  max(a,b) (a>b?a:b)
#define  min(a,b) (a>b?b:a)
#define  PI acos(-1.0)
#define  fir first
#define  sec second
#define  SZ(x) (x.size())
#define  inf 0x3f3f3f3f
#define  PB push_back
#define  MP make_pair
#define  all(x) (x).begin(),(x).end()
#define  PII pair<int,int>
#define  E 2.7182818284590452353602874713527
using namespace std;

/**********************************************Head-----Template****************************************/
bool Finish_read;
template<class T>inline void read(T &x){Finish_read=0;x=0;int f=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')f=-1;if(ch==EOF)return;ch=getchar();}while(isdigit(ch))x=x*10+ch-'0',ch=getchar();x*=f;Finish_read=1;}
template<class T>inline void print(T x){if(x/10!=0)print(x/10);putchar(x%10+'0');}
template<class T>inline void writeln(T x){if(x<0)putchar('-');x=abs(x);print(x);putchar('\n');}
template<class T>inline void write(T x){if(x<0)putchar('-');x=abs(x);print(x);}
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
//const ll mod = 10000019;
//const ll phi_mod_prime=mod-1;
ll ksm(ll a,ll b,ll mod){ll ans=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1) ans=ans*a%mod;a=a*a%mod;}return ans;}
ll phi(ll n){ ll rea=n;for(ll i=2;i*i<=n;i++){if(n%i==0){ rea=rea-rea/i;while(n%i==0) n/=i;}}if(n>1) rea=rea-rea/n;return rea;}
//a^(b%modhi(mod)+phi(mod))%mod;
void exgcd(int a,int b,int &x,int &y,int &d){if(!b){x=1;y=0;d=a;}else exgcd(b,a%b,y,x,d),y-=a/b*x;}
inline int inv(int a,int mod){int x,y,d;exgcd(a,mod,x,y,d);x=(x%mod+mod)%mod;return x;}
/********************************Head----Template**********************************************/


int main(){
    int n,x;cin>>n>>x;
    int sum=0;
    for(int i=1;i<=n;i++) {
        int y;cin>>y;
        sum+=y;
        if(sum==x) {cout<<i+1<<endl;return 0;}
        if(sum>x) {cout<<i<<endl;return 0;}
    }
    cout<<n+1<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int n; cin >> n;
    if (n == 1)
    {
        cout << "Hello World\n";
    } else {
        int a,b; cin >> a >> b;
        cout << a+b << endl;
    }
    return 0;
}

Measured memory_bytes: 256
/*
ID: barish21
LANG: C++14
TASK: test
*/

/****Author: Barish Namazov****/
#include <bits/stdc++.h>

using namespace std;

/***TEMPLATE***/
#define intt long long

#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

#define F first
#define S second
#define pb push_back

#define IO ios_base::sync_with_stdio(false);cin.tie();

const intt max1 = 11;
const intt max2 = 102;
const intt max3 = 1003;
const intt max4 = 10004;
const intt maxx = 200005;
const intt max6 = 1000006;
const intt max7 = 10000007;
const intt lg2 = 7;
const intt lg3 = 10;
const intt lg4 = 13;
const intt lg5 = 17;
const intt lg6 = 20;
const intt lg7 = 24;
const intt lg8 = 27;
const intt lg9 = 30;
const intt lg18 = 60;
const intt INF = 2LL * 1000000000;
/***************/

/***Additional Functions***/
intt powmod(intt a,intt b,intt mod){intt res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
intt gcd(intt a, intt b) { while(b) b ^= a ^= b ^= a %= b; return a;}
intt lcm(intt a,intt b){return a*b/gcd(a,b);}
intt is_prime(intt n){if(n==1)return 0;if(n==2)return 1;if(n%2==0)return 0;for(intt i=3;i<=sqrt(n);i+=2)if(n%i==0)return 0;return 1;}
intt is_integer(double n){if(floor(n)==ceil(n))return 1;return 0;}

intt sto_int(string s){stringstream ss(s);intt n;ss>>n;return n;}
string to_string(intt n){stringstream ss;ss<<n;string s=ss.str();return s;}
/**************************/

intt arr[maxx];
int main() {
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    IO;
    intt n;
    cin >> n;
    for (intt i = 1; i <= n; i++)
        cin >> arr[i];
    for (intt i = n; i >= 1; i -= 2)
        cout << arr[i] << " " ;
    for (intt i = (n % 2 == 0 ? 1 : 2); i <= n; i += 2)
        cout << arr[i] << " ";
    cout << endl;
    return 0;
}


Measured memory_bytes: 4348
n = int(input())
s = list(input())

ans = n - 1
w = [0]
for i in range(n - 1):
    w.append(w[-1])
    if s[i] == 'W':
        w[-1] += 1
e = [0 for _ in range(n)]
for i in range(n - 1, 0, - 1):
    e[i - 1] = e[i]
    if s[i] == 'E':
        e[i - 1] += 1
for i in range(n):
    ans = min(ans, e[i] + w[i])
print(ans)

Measured memory_bytes: 82340
N, M, K = map(int, input().split(' '))
A_ls = [0] + list(map(int, input().split(' ')))
B_ls = [0] + list(map(int, input().split(' ')))

for i in range(1, N + 1):
    A_ls[i] += A_ls[i - 1]
for i in range(1, M + 1):
    B_ls[i] += B_ls[i - 1]

b_cnt, rst = M, 0
for a_cnt in range(N + 1):
    if A_ls[a_cnt] > K:
        break
    while A_ls[a_cnt] + B_ls[b_cnt] > K:
        b_cnt -= 1
    rst = max(rst, a_cnt + b_cnt)
print(rst)

Measured memory_bytes: 39876
#include <iostream>
using namespace std;
int main()
{
long long signed int N,K,a;
cin>>N>>K;
if(K==0)
{
    cout<<N;
}
a=N%K;
if(abs(a-K)<=a)
cout<<abs(a-K);
else
cout<<a;
return 0;
}

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

#define int long long

typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

int N,D;
string S;
string T;
signed main(){
    cin>>N>>S>>D;
    T=S;
    int cnt=0;
    for(int i=0;i<T.size()&&cnt<D;i++){
        if(T[i]=='0'){
            cnt++;
            T[i]='1';
        }
    }

    for(int i=T.size()-1;i>=0&&cnt<D;i--){
        if(S[i]=='1'){
            T[i]='0';
            cnt++;
        }
    }

    cout<<T<<endl;
    return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
	int a, p;
	cin >> a >> p;
	cout << (a * 3 + p) / 2;
}

int main()
{
	fastio;
	solve();

	return 0;
}

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

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

typedef long long ll;

const int mod = 1e9 + 7;

using namespace std;



int main(void) {
	int N, Q; cin >> N >> Q;
	string S; cin >> S;
	vector<int> l(Q), r(Q);
	rep(i, Q) {
		cin >> l[i] >> r[i];
		l[i]--;
		r[i]--;
	}

	rep(i, S.size()-1) {
		if (S[i] == 'A' && S[i + 1] == 'C') {
			S[i] = '@';
		}
	}

	vector<int> sum(S.size(), 0);
	sum[0] = (int)(S[0] == '@');
	for(int i = 1;i < S.size();i++) {
		sum[i] = sum[i - 1];
		sum[i] += (int)(S[i] == '@');
	}

	rep(q, Q) {
		int ans = sum[r[q]-1] - sum[l[q]];
		ans += (int)(S[l[q]] == '@');
		cout << ans << endl;
	}

	return 0;
}

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

using namespace std;

int n;
char s[4010];
int main()
{
  	cin >> n;
  int num[3] = {};
  	for(int i = 1; i <= n; i++)
    {
		cin >> s[i];
      	if(s[i] == 'R')
        {
          num[0]++;
        }
      else if(s[i] == 'G')
      {
        num[1]++;
      }
      else
      {
        num[2]++;
      }
    }
      long long ans = 1ll * num[0] * num[1] * num[2];
      long long minum = 0;
      int eq = 'R' + 'G' + 'B';
      for(int i = 1; i <= n; i++)
      {
			for(int d = 1; i + d + d <= n;d++)
            {//s[i], s[i+d], s[i+d+d]
				if(s[i] + s[i+d] + s[i+d+d] == eq)
                {
					minum++;
                }
            }
      }
      ans = ans - minum;
      cout << ans << endl;
	return 0;
}

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

int convert(string s){
	int h=(s[0]-'0')*10+(s[1]-'0');
	int m=(s[3]-'0')*10+(s[4]-'0');
	int t=(s[6]-'0')*10+(s[7]-'0');
	return h*3600+m*60+t;
}

class range{
public:
	int left,right;
	range(int left,int right):left(left),right(right){}
	range(){};
};

bool is_connect(range a,range b){
	if(a.right<=b.left || b.right<=a.left) return false;
	return true;
}


int main()
{
	int n;
	while(cin>> n && n!=0){
		vector<range> V(n);
		for(int i=0;i<n;i++){
			string s,t;cin>>s>>t;
			V[i].left=convert(s);
			V[i].right=convert(t);
		}

		int ans[24*3600+60*60+60+1];
		memset(ans,0,sizeof(ans));
		for(int i=0;i<n;i++){
			for(int k=V[i].left;k<V[i].right;k++){
				ans[k]++;
			}
		}

		int res=0;
		for(int i=0;i<=24*3600+60*60+60;i++){
			res=max(res,ans[i]);
		}
		cout<<res<<endl;



	}
	return 0;
}

Measured memory_bytes: 1356
import math
N, D = map(int, input().split())
x = [0] * N
y = [0] * N
cnt = 0

for i in range(N):
    x[i], y[i] = map(int, input().split())

for i in range(N):
    xx = x[i]**2 + y[i]**2
    dis = math.sqrt(xx)

    if dis <= D:
        cnt=cnt+1

print(cnt)

Measured memory_bytes: 24668
#include <iostream>

using namespace std;

int main()
{
    int a,b;
    cin>>a>>b;
    string one="";
    string two="";
    for(int i=0;i<b;i++){
        one+=to_string(a);
    }
    for(int i=0;i<a;i++){
        two+=to_string(b);
    }
    if(one[0]<two[0])cout<<one;
    else cout<<two;


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <string>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;


int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}
void check(long long a,long long b,long long c,long long d){
    long long same=a;
    a = a-b;
    while(same != a && a >= 0){
        cout << a << endl ;
        if(a <= c){
            a += d;
            if(a == same){
                cout << "Yes" << endl;
                return;
            }
        }
        a = a-b ;
    }

    if(a<0)
        cout << "No" << endl;
    return;
}


int main(int argc, const char * argv[]) {
    
    // source code
    string S,T;
    cin >> S;
    cin >> T;
    int flg=0;
    int c=0;
    char t[T.size()];
    // rep(i,T.size()){
    //     if(S[0] == T[i]){
    //         start = i;
    //         break;
    //     }
    // }
    // while(c<S.size()){
    //     if(start==T.size())
    //         start = 0;
    //     if(S[c] != T[start]){
    //         cout << "No" << endl;
    //         break;
    //     }else{
    //         c++;
    //         start++;
    //     }
    // }
    // if(c == S.size())
    //     cout << "Yes" << endl;
    while(c<T.size()){
        char tmp = T[0];
        rep(i,T.size()-1){
            T[i]=T[i+1];
        }
        c++;
        T[T.size()-1]=tmp;
        if(S == T){
            flg = 1 ;
            break;
        }
    }
    if(flg == 1)
        cout <<  "Yes" << endl;
    else
        cout <<  "No" << endl;
}

Measured memory_bytes: 256
s = input()
if s == "SUN":
    print(7)
elif s == "MON":
    print(6)
elif s == "TUE":
    print(5)
elif s == "WED":
    print(4)
elif s == "THU":
    print(3)
elif s == "FRI":
    print(2)
elif s == "SAT":
    print(1)





Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <deque>
#include <set>
#include <cmath>
#include <bits/stdc++.h>
#include <limits>

#define MOD 1000000007
//#define MOD 7

using namespace std;

int main(void){
    // Your code here!
    vector<long long> x(3, 0);
    
    cin >> x[0] >> x[1] >> x[2];
    
    sort(x.begin(), x.end());
    
    cout << x[2] - x[1] + x[1] - x[0] << endl;
    
    return 0;
}

Measured memory_bytes: 256
n, x = map(int,input().split())
l = list(map(int,input().split()))
if sum(l) <= x:
    print(n+1)
else:
    i, d = 0, 0
    while i<n and d <= x:
        d += l[i]
        i += 1
    if d == x and i == n:
        print(i+1)
    else:
        print(i)

Measured memory_bytes: 9132
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define rt return
using dbl = double;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vi p(N);
    rep(i, N) {
        cin >> p[i]; p[i]--;
    }
    int ans = 0;
    rep(i, N - 1) {
        if (p[i] == i) {
            swap(p[i], p[i + 1]);
            ans++;
        }
    }
    if (p[N - 1] == N - 1)ans++;
    cout << ans << endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
int inf=100000000000000007;
signed main(){
  int h,n;cin>>h>>n;
  vector<int> a(n);
  vector<int> b(n);
  rep(i,n)cin>>a[i]>>b[i];
  vector<int> dp(2*h+3,inf);
  dp[0]=0;
  rep(i,n){
    a[i]=min(h,a[i]);
    rep(j,2*h+3){
      if(j>=a[i])dp[j]=min(dp[j],dp[j-a[i]]+b[i]);
    }
  }
  int res=inf;
  for(int i=h;i<2*h+3;i++){
    res=min(res,dp[i]);
  }
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 384