akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <utility>
#include <cctype>
#include <vector>
using namespace std;

#ifdef __linux
#define _U(s) s##_unlocked
#else
#define _U(s) _##s##_nolock
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
#define gcu _U(getchar)
#define pcu _U(putchar)
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
#define _OP(t) inline operator t()
struct _in {
#ifdef _GLIBCXX_STRING
	_OP(string){string s;char c;while(isspace(c = gcu()));do{s+=c;}while(c=gcu(),c!=' '&&c!='\n'&&c!=EOF);return s;}
#define _S
#endif
	_OP(char){char c=gcu();gcu();return c;}
	_OP(double){double d; scanf("%lf",&d); gcu();return d;}
	_T _OP(T){T n{},m{1},c;while(isspace(c = gcu()));if(c=='-')m=-1,c=gcu();do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
} in;
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
#ifdef _S
_SCAN(string &o) {int c{gcu()};if(c==EOF)return false;else{ungetc(c,stdin);string t=move(in);o=t;return true;}}
#endif
_T _SCAN(T &o) {int c{gcu()};return c==EOF?false:(ungetc(c,stdin),o=in,true);}
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);}
_OUT(const char *s){while(*s)pcu(*s++);}
_OUT(char c){pcu(c);}
#ifdef _S
_OUT(string &s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
	_T _OUT(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
	_HT _OUT(H &&h, T... t){out(h);out(t...);}
	template <typename... T> _OUTL(T... t){out(t...);outl();}
	struct range{
		int e,b=0,s=1;range(int _b,int _e,int _s):e(_e),b(_b),s(_s){} range(int _b,int _e): e(_e), b(_b){} range(int _e):e(_e){}
		struct it{int v,s; it(int _v,int _s):v(_v),s(_s){} operator int()const{return v;} operator int&(){return v;}int operator*()const{return v;}
			it& operator++(){v+=s;return *this;} }; it begin(){return {b,s};} it end(){return {e,s};}};
#define times(i,n) for(int i=n;i;i--)

int main() {
	int a {in}, b {in}, c {in}, d {a + b}, r {c};
	vector<bool> v(d);
	for (; !v[r % d]; r += 60)
		if (r % d <= a) {
			outl(r);
			return 0;
		} else
			v[r % d] = true;
	outl(-1);
}


Measured memory_bytes: 2612
N = int(input())
A = list(map(int,input().split()))
A.insert(0,0)
A.append(0)
cost = []
for i in range(N+1):
    cost.append(abs(A[i+1]-A[i]))
seed_of_ans = sum(cost)
for i in range(N):
    L = [A[i+2],A[i+1],A[i]]
    L.sort()
    if max(L) == A[i+1] or min(L) == A[i+1]:
        print(seed_of_ans-abs(A[i+2]-A[i+1])-abs(A[i+1]-A[i])+abs(A[i+2]-A[i]))
    else:
        print(seed_of_ans)

Measured memory_bytes: 14172
#include <stdio.h>
int main()
{
  int i,n,j,count = 0;
  scanf("%d",&n);
  for(int i=1;i<=n;i++)
  {
    scanf("%d" ,&j);
    if( j != i )
      count++;
  }
  if( count == 0 || count == 2)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}

Measured memory_bytes: 1656
def div2 h,w
  
  h,w = [h, w].sort
  
  return [h*w/2, h*w/2] if h % 2 == 0 or w % 2 == 0
  return [w/2*h, (w+1)/2*h]
end
  
def f h,w
  
  return 0 if h % 3 == 0 or w % 3 == 0
  
  res0 = res1 = h*w
  
  0.upto h%3 do |i|
    
    s = w*(h/3 + i)
    ss =div2(h-h/3-i, w).push(s)
    # p ss
    
    res0 = [res0, ss.max - ss.min].min
  end
  
  0.upto w%3 do |i|
    
    s = h*(w/3 + i)
    # p s
    ss =div2(w-w/3-i, h).push(s)
    # print s
    # p ss
    res1 = [res1, ss.max - ss.min].min 
  end
  
  # p [res0, res1]
  [res0, res1].min
end  

H, W = gets.split.map(&:to_i).sort

puts [f(H,W), f(W,H)].min


# a b c d
# a*W

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k;
	scanf("%d %d",&n,&k);
	vector<int> v(n);
	for(int&x:v) scanf("%d",&x);
	vector<int> dp(n+1,1e9);
	dp[0] = 0;
	for(int i = 1; i < n; i++)
		for(int j = 1; j <= k; j++)
			if(i-j >= 0)
				dp[i] = min(dp[i], dp[i-j]+abs(v[i]-v[i-j]));
	printf("%d\n", dp[n-1]);
	return 0;
}
/*
5 3
10 30 40 50 20
0  20

*/ 

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rept(i,k,n) for(ll i = (k); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<long long,long long> Pll;
# define MOD  998244353LL

template <typename T>
ostream& operator<<(ostream& s, const vector<T> &vec){
    for(int i=0;i<vec.size();i++){
        if(i) s << ',';
        else s << '{';
        s <<setw(2)<< vec[i];
    }
    s << '}' << endl;
    return s;
}


template <typename T>
T powm(T a, T b, T mod=MOD){
    if(b && b%2){
        return a*powm(a*a,b/2)%mod;
    }else if(b){
        return powm(a*a,b/2)%mod;
    }else{
        return 1;
    }
}
long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}
int main(){
    ll n,m,k;
    cin>>n>>m>>k;
    ll dp = m;
    rep(i,n-k-1) dp=dp*(m-1)%MOD;
    ll ans =0;
    vector<ll> con(n,1);
    rept(i,1,n){
        con[i]=con[i-1]*(n-i)%MOD*modinv(i)%MOD;
    }
    for(ll i=k;i>=0;i--){
        ans += dp*con[i]%MOD;
        ans %=MOD;
        dp=dp*(m-1)%MOD;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4840
R=range
K=4000
S=[input()for i in R(3)]
A,B,C=S
a,b,c=[len(i)for i in S]
def F(S,T):
 Q=[1]*(K*2+1)
 for i in R(-len(T),len(S)):
  for j in R(max(i,0),min(len(S),len(T)+i)):
   if len(set([S[j],T[j-i],'?']))>2:Q[i]=0
 return Q
S=F(A,B)
T=F(A,C)
U=F(B,C)
m=K*3
for p in R(-K,K+1):
 if S[p]!=0:
  for q in R(-K,K+1):
   if T[q]!=0 and U[q-p]!=0:
    m=min(m,max(p+b,q+c,a)-min(p,q,0))
print(m)


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

using namespace std;

int main(void) {
    int n, m;
    double sum = 0;
    int flag = 0;

    cin >> n >> m;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        int tem;
        cin >> tem;
        a[i] = tem;

        sum = sum + tem;
    }

    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());

    for(int i = 0; i < m; i++){
        //cout << "a[" << i << "]=" << a[i] <<endl;
        //cout << sum / (4 * m) << endl;
        if(a[i] < sum / (4 * m)){
            flag = 0;
            break;
        }
        else{
            flag = 1;
        }
    }

    //cout << "falg=" << flag << endl;

    if(flag == 0){
        cout << "No" << endl;
    }
    else if(flag == 1){
        cout << "Yes" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<functional>
#include<utility>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;

int n;
int v[100], c[100];

int main() {
	cin >> n;
	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		cin>>v[i];
	}
	for (int i = 0; i < n; i++)
	{
		cin >> c[i];
		if (c[i]<v[i])
		{
			ans += v[i] - c[i];
		}
	}
	cout << ans << endl;
}

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

int main() {
	int N;
	cin >> N;	
	int Na = N % 1000;
	int Nb = N % 1110;

	if (N % 1111 == 0 || Na % 111 == 0 || Nb < 10) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100001,INF=1<<30;

ll rui(ll a,ll b){
    if(b==1) return a%mod;
    else if(b==0) return 1;
    else if(b%2==0) return (rui(a,b/2)*rui(a,b/2))%mod;
    else return (rui(a,b-1)*a)%mod;
}

ll inv[MAX],fac[MAX],finv[MAX];

void make(){
    
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    
    for(int i=2;i<MAX;i++){
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        fac[i]=fac[i-1]*(ll)i%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }
    
}

ll comb(ll a,ll b){
    if(a<b) return 0;
    return fac[a]*(finv[b]*finv[a-b]%mod)%mod;
}

int main(){

    int N,K;cin>>N>>K;
    make();
    ll dp[N+1][K+1];
    for(int i=0;i<N+1;i++){
        for(int j=0;j<K+1;j++){
            dp[i][j]=0;
        }
    }
    
    dp[1][1]=1;
    for(int i=1;i<=N;i++){
        for(int j=1;j<=K;j++){
            if(i==1&&j==1) continue;
            dp[i][j]=(dp[i-1][j]*j+dp[i-1][j-1])%mod;
        }
    }
    
    ll ans=0;
    
    for(int j=1;j<=K;j++){
        ans+=dp[N][j];
        ans=ans%mod;
    }
    
    cout<<ans<<endl;
}




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

int main(){
  int64_t N;
  cin >> N;
  vector<int64_t> A(N);
  set<int64_t> S;
  for(int64_t i=0; i<N; i++){
    cin >> A.at(i);
    S.insert(-A.at(i));
    A.at(i)*=-1;
  }
  sort(A.begin(), A.end());
  for(int64_t i=0; i<N; i++){
    A.at(i)*=-1;
  }
  int64_t Ans=0;
  int64_t K=S.size();
  vector<pair<int64_t, int64_t>> P(K);
  for(int64_t i=0; i<K; i++){
    P.at(i)=make_pair(-*S.begin(), 0);
    S.erase(S.begin());
  }
  int64_t h=0;
  for(int64_t i=0; i<N; i++){
    if(i!=0){
      if(A.at(i)!=A.at(i-1)){
        h++;
      }
    }
    P.at(h).second++;
  }
  vector<int64_t> Place(K);
  h=0;
  int64_t j=0;
  for(int64_t i=0; i<N; i++){
    if(i!=0){
      if(A.at(i)!=A.at(i-1)){
        h++;
      }
    }
    if(i==0){
      Place.at(0)++;
    }
    else if(Place.at(j)>0){
      Ans+=P.at(j).first;
      Place.at(j)--;
      Place.at(h)+=2;
    }
    else if(Place.at(j)==0){
      j++;
      Ans+=P.at(j).first;
      Place.at(j)--;
      Place.at(h)+=2;
    }
  }
  cout << Ans << endl;
}

Measured memory_bytes: 17244
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

bool is_complete(vector<ll> &b) {
    for (ll i = b.size(); i--;) {
        if (b[i] != i+1) {
            return false;
        }
    }
    return true;
}

int main() {

    ll n;
    while (cin >> n, n) {

        vector<ll> b(n);
        for (ll i = 0; i < n; i++) {
            cin >> b[i];
        }

        if (is_complete(b)) {
            cout << 0 << endl;
            continue;
        }

        constexpr ll limit = 10000;
        for (ll i = 1; i <= limit; i++) {

            ll r = b.size();
            for (ll i = r; i--; ) {
                if (--b[i] <= 0) b.erase(b.begin() + i);
            }
            b.push_back(r);

            if (is_complete(b)) {
                cout << i << endl;
                break;
            }

            if (i == limit) {
                cout << -1 << endl;
                break;
            }

        }

    }

}


Measured memory_bytes: 3144
#include<stdio.h>
#include<string.h>
#define mod 1000000007
#define ll long long
int min(int a, int b){return a < b ? a : b;}
int main(){
    int n;
    scanf("%d",&n);
    ll a[n + 1];
    ll summod[n + 1];
    for(int i = 0; i < n; i++){
        scanf("%lld",&a[i + 1]);
    }
    summod[n] = a[n];
    for(int i = n - 1; i > 0; i--){
        summod[i] = summod[i + 1] + a[i];
        summod[i] %= mod;
    }
    ll ans = 0;
    for(int i = 1; i < n; i++){
        ans += a[i] * summod[i + 1];
        ans %= mod;
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 4856
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

int main()
{
	int N, Y;
	cin >> N >> Y;
	int tt = 10000, t = 5000, h = 1000;
	int l = 0;
	for (int i = 0; i <= Y / tt; i++) {
		for (int j = 0; j <= (Y - (i * tt)) / t; j++) {
			if ((Y - (i * tt + j * t)) % h == 0) {
				l = ((Y - (i * tt + j * t)) / h);
				if (i + j + l == N) {
					cout << i << " " << j << " " << l << endl;
					return 0;
				}
			}
		}
	}
	cout << -1 << " " << -1 << " " << -1 << endl;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  while(cin >> n &&n){
    vector<pii> v(n,make_pair(0,0));
    ll a,b,c;
    rep(i,n){
      cin >> a >> b >> c;
      v[i].fi = a;
      v[i].se = b + c;
    }
    sort(all(v),[](const pii &a,const pii &b){
          return a.se > b.se;
        });
    cout << v[0].fi << " " << v[0].se << endl;
  }
  return 0;
}

Measured memory_bytes: 3192
#include <iostream>
using namespace std;
int main() {
    char moji;
    cin >> moji;
    if (moji == 'a'){
        cout << "vowel" << endl;
    } else if (moji == 'i'){
        cout << "vowel" << endl;
    } else if (moji == 'u'){
        cout << "vowel" << endl;
    } else if (moji == 'e'){
        cout << "vowel" << endl;
    } else if (moji == 'o'){
        cout << "vowel" << endl;
    } else{
        cout << "consonant" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int r = Integer.parseInt(sc.next());

        int result = 0;
        if (n < 10) {
            result = r + (100 * (10 - n));
        } else {
            result = r;
        }

        System.out.println(result);

        sc.close();
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;



int main(){
    ll n; cin >> n;
    ll ans = 1;
    for(ll i=1; i<=n; i++){
        ans *= i % MOD;
        ans %= MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

bool input(char b[][8])
{
	char dummy;
	for (int i=0; i<8; i++) {
		for (int j=0; j<8; j++) {
			if ( !(cin >> b[i][j]) ) return false;
		}
		//cin >> dummy;
	}
	return true;
}

int main()
{
	char board[8][8];
	
	while ( input(board) ) {
		pair<int, int> block_pos[4];
		int found_cnt = 0;
		for (int i=0; i<8; i++) {
			for (int j=0; j<8; j++) {
				if (board[i][j] == '1') {
					block_pos[found_cnt].first  = i;
					block_pos[found_cnt].second = j;
					found_cnt++;
					if (found_cnt == 4) break;
				}
			}
		}
		
		if ( block_pos[0].first == block_pos[1].first ) {
			// current candidates : A,C,E,G
			if ( block_pos[0].second == block_pos[2].second ) cout << "A";
			// C,E,G
			else if ( block_pos[1].first == block_pos[2].first ) cout << "C";
			// E,G
			else if ( block_pos[1].second == block_pos[2].second ) cout << "E";
			// G
			else cout << "G";
		}
		// current candidates : B,D,F
		else if (block_pos[0].second != block_pos[1].second) cout << "D";
		else {
			// current candidates : B,F
			if ( block_pos[1].second == block_pos[2].second ) cout << "B";
			// F
			else cout << "F";
		}
		cout << endl;
	}
	
	return 0;
}

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

int main() {
    int K, X;
    cin >> K >> X;
    int mn = X - K + 1;
    int ans = mn;
    rep(i, 2*K - 1) {
        cout << mn << endl;
        mn += 1;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

int main(void){
	int a,b;
	cin>>a>>b;
	if(a>=13){
		cout<<b<<endl;
	}else if(a>=6){
		cout<<b/2<<endl;
	}else{
		cout<<0<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    string S;
    cin >> S;
    vector<ll> r,g,b;
    rep(i,0,N){
        if(S[i] == 'R') r.push_back(i);
        else if(S[i] == 'G') g.push_back(i);
        else b.push_back(i);
    }

    ll ans = 0;

    rep(i,0,N){
        ll res = 0;
        if(S[i] == 'R'){
            ll c1 = lower_bound(g.begin(), g.end(), i) - g.begin();
            ll c2 = lower_bound(b.begin(), b.end(), i) - b.begin();
            c2 = b.size() - c2;
            res += c1 * c2;
            for(ll j = 1; (i-j) >= 0 && i+j < N; j++){
                if(S[i-j] == 'G' && S[i+j] == 'B') res--;
            }

            ll c3 = lower_bound(b.begin(), b.end(), i) - b.begin();
            ll c4 = lower_bound(g.begin(), g.end(), i) - g.begin();
            c4 = g.size() - c4;
            res += c3 * c4;
            for(ll j = 1; (i-j) >= 0 && i+j < N; j++){
                if(S[i-j] == 'B' && S[i+j] == 'G') res--;
            }
        }else if(S[i] == 'G'){
            ll c1 = lower_bound(r.begin(), r.end(), i) - r.begin();
            ll c2 = lower_bound(b.begin(), b.end(), i) - b.begin();
            c2 = b.size() - c2;
            res += c1 * c2;
            for(ll j = 1; (i-j) >= 0 && i+j < N; j++){
                if(S[i-j] == 'R' && S[i+j] == 'B') res--;
            }

            ll c3 = lower_bound(b.begin(), b.end(), i) - b.begin();
            ll c4 = lower_bound(r.begin(), r.end(), i) - r.begin();
            c4 = r.size() - c4;
            res += c3 * c4;
            for(ll j = 1; (i-j) >= 0 && i+j < N; j++){
                if(S[i-j] == 'B' && S[i+j] == 'R') res--;
            }
        }else{
            ll c1 = lower_bound(g.begin(), g.end(), i) - g.begin();
            ll c2 = lower_bound(r.begin(), r.end(), i) - r.begin();
            c2 = r.size() - c2;
            res += c1 * c2;
            for(ll j = 1; (i-j) >= 0 && i+j < N; j++){
                if(S[i-j] == 'G' && S[i+j] == 'R') res--;
            }

            ll c3 = lower_bound(r.begin(), r.end(), i) - r.begin();
            ll c4 = lower_bound(g.begin(), g.end(), i) - g.begin();
            c4 = g.size() - c4;
            res += c3 * c4;
            for(ll j = 1; (i-j) >= 0 && i+j < N; j++){
                if(S[i-j] == 'R' && S[i+j] == 'G') res--;
            }
        }
        ans += res;
    }
    print(ans);
}

Measured memory_bytes: 3728
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC085_C
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] ny = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int N = ny[0];
            int Y = ny[1];

            for (int i = 0; i <= N; i++)
            {
                for (int j = 0; j <= N - i; j++)
                {
                    int k = N - i - j;
                    int value = 10000 * i + 5000 * j + 1000 * k;
                    if (value == Y)
                    {
                        Console.WriteLine("{0} {1} {2}", i, j, k);
                        return;
                    }
                }
            }
            Console.WriteLine("-1 -1 -1");
        }
    }
}


Measured memory_bytes: 28308
n = int(input())
lis = [int(input()) for i in range(n)]
li = [-1 for i in range(n)]
for i in range(n):
    li[lis[i]-1] = i
cnt = 0
ans = n-1
for i in range(n-1):
    if li[i] < li[i+1]:
        cnt += 1
    else:
        ans = min(ans,n-1-cnt)
        cnt = 0
ans = min(ans,n-1-cnt)
print(ans)

Measured memory_bytes: 18888
#include <stdio.h>

int main() {
	int i, j, k, n, v;
	int a[100];

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}

	for (i = 0; i < n; i++) {
		v = a[i];
		j = i - 1;

		while (j >= 0 && a[j] > v) {
			a[j+1] = a[j];
			a[j] = v;
			j--;
		}

		for (k = 0; k < n - 1; k++) {
			printf("%d ", a[k]);
		}

		printf("%d\n", a[n - 1]);
	}

	return 0;
}

Measured memory_bytes: 596
import sys
sys.setrecursionlimit(1000000000)

import copy

H, W = map(int, input().split())
A = [list(input()) for _ in range(H)]

B = copy.deepcopy(A)
for h in range(H):
    for w in range(W):
        B[h][w] = A[h][w] == "."

def dfs(h, w, C):
    if h == H or w == W:
        return False
    if A[h][w] == ".":
        return False
    X = copy.deepcopy(C)
    X[h][w] = True
    if [h,w] == [H-1,W-1]:
        tmp = True
        for x in X:
            tmp = tmp and all(x)
        return tmp
    return dfs(h+1, w, X) or dfs(h, w+1, X)

print("Possible" if dfs(0,0,B) else "Impossible")

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define repi(i,a,b) for(int i = (a); i<= (b); i++)
#define repA(i,n) for(int i=n; i>=0; i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (int)(a.size())

typedef long long ll;
typedef long double ld;
const ll mod = (ll)(1e9+7);//998244353;
const int N = (int)(1e6+5);

void pre() {

}

void solve() {
  int n;  cin>>n;
  int cnt = 0;
  rep(i,n) {
    int x;  cin>>x;
    if(i%2 == 0) {
      if(x%2) cnt++;
    }
  }
  cout<<cnt<<'\n';
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
  #endif
  int t = 1;
  pre();
  //cin>>t;
  rep(i,t)  {
//    cout<<"\nCase #"<<(i+1)<<"\n";
    solve();
    cout<<'\n';
  }
  return 0;
}


Measured memory_bytes: 3624
//DSL_2C
#include <cstdio>
#include<algorithm>
#include <vector>
using namespace std;
 
class Node{
public:
 int location;
 int p,l,r;
 Node(){}
};

class Point{
public:
 int id,x,y;
 Point(){}
 Point(int id,int x,int y): id(id),x(x),y(y) {}
 bool operator < (const Point &p) const{
  return id<p.id;
 }
 void print(){
  printf("%d\n",id);
 }
};

static const int MAX=1000000;
static const int NIL=-1;
int N;
Point P[MAX];
Node T[MAX];
int np;

bool lessX(const Point &p1,const Point &p2){return p1.x<p2.x;}
bool lessY(const Point &p1,const Point &p2){return p1.y<p2.y;}

int makeKDTree(int l,int r,int depth){
 if(!(l<r)) return NIL;
 int mid=(l+r)/2;
 int t=np++;
 if(depth%2==0){
  sort(P+l,P+r,lessX);
 }else{
  sort(P+l,P+r,lessY);
 }
 T[t].location=mid;
 T[t].l=makeKDTree(l,mid,depth+1);
 T[t].r=makeKDTree(mid+1,r,depth+1);
 return t;
}

void find(int v,int sx,int tx,int sy,int ty,int depth,vector<Point> &ans){
 int x=P[T[v].location].x;
 int y=P[T[v].location].y;
 if(sx<=x && x<=tx && sy<=y && y<=ty){
  ans.push_back(P[T[v].location]);
 }
 if(depth%2==0){
  if(T[v].l!=NIL){
   if(sx<=x) find(T[v].l,sx,tx,sy,ty,depth+1,ans);
  }
  if(T[v].r!=NIL){
   if(x<=tx) find(T[v].r,sx,tx,sy,ty,depth+1,ans);
  }
 }else{
  if(T[v].l!=NIL){
   if(sy<=y) find(T[v].l,sx,tx,sy,ty,depth+1,ans);
  }
  if(T[v].r!=NIL){
   if(y<=ty) find(T[v].r,sx,tx,sy,ty,depth+1,ans);
  }
 }
}

int main(){
 int x,y;
 scanf("%d",&N);
 for(int i=0;i<N;i++){
  scanf("%d %d",&x,&y);
  P[i]=Point(i,x,y);
  T[i].l=T[i].r=T[i].p=NIL;
 }
 
 np=0;
 int root=makeKDTree(0,N,0);
 int q;
 scanf("%d",&q);
 int sx,tx,sy,ty;
 vector<Point> ans;
 for(int i=0;i<q;i++){
  scanf("%d %d %d %d",&sx,&tx,&sy,&ty);
  ans.clear();
  find(root,sx,tx,sy,ty,0,ans);
  sort(ans.begin(),ans.end());
  for(int j=0;j<ans.size();j++){
   ans[j].print();
  }
  printf("\n");
 }
 return 0;
}

Measured memory_bytes: 17416
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

#define iFOR(idx, from, upto) for (int  idx = from; idx < upto; ++idx)
#define lFOR(idx, from, upto) for (long idx = from; idx < upto; ++idx)

#define ll long long

using namespace std;

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

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

    vector<int> b(n);
    for (int i = 0; i < n - 1; i++) b[i] = a[i+1] - a[i];
    b[n-1] = a[0] - a[n-1] + k;

    cout << accumulate(b.begin(), b.end(), 0) - *max_element(b.begin(), b.end()) << endl;

    return 0;
}


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

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;

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

	int n;
	cin >> n;
	int d = n % 10;
	
	string s;
	if(d == 3) s = "bon";
	else if(d == 0 || d == 1 || d == 6 || d == 8) s = "pon";
	else s = "hon";
	
	cout << s << endl;
	
	return 0; 
}

Measured memory_bytes: 3600
//start of jonathanirvings' template v3.0.3 (BETA)

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;

double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};

#ifdef TESTING
  #define DEBUG fprintf(stderr,"====TESTING====\n")
  #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
  #define debug(...) fprintf(stderr, __VA_ARGS__)
#else
  #define DEBUG 
  #define VALUE(x)
  #define debug(...)
#endif

#define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
#define FORD(a,b,c) for (int (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (int (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define REP(i,n) FOR(i,0,n)
#define REPN(i,n) FORN(i,1,n)
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)

inline string IntToString(LL a){
  char x[100];
  sprintf(x,"%lld",a); string s = x;
  return s;
}

inline LL StringToInt(string a){
  char x[100]; LL res;
  strcpy(x,a.c_str()); sscanf(x,"%lld",&res);
  return res;
}

inline string GetString(void){
  char x[1000005];
  scanf("%s",x); string s = x;
  return s;
}

inline string uppercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
  return s;
}

inline string lowercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
  return s;
}

inline void OPEN (string s) {
  #ifndef TESTING
  freopen ((s + ".in").c_str (), "r", stdin);
  freopen ((s + ".out").c_str (), "w", stdout);
  #endif
}

//end of jonathanirvings' template v3.0.3 (BETA)

int n;
int a[200005];
map<LL,int> ada;

int main()
{
  LL risan = 0;
  LL now = 0;
  scanf("%d",&n);
  ada[0] = 1;
  REP(i,n)
  {
    scanf("%d",&a[i]);
    now += a[i];
    risan += ada[now];
    ++ada[now];
  }
  printf("%lld\n",risan);
  return 0;
}











Measured memory_bytes: 13568
S = input()

ans = "Yes"
for i in range(len(S)):
    if i % 2 == 0:
        if not S[i] in ["R", "U", "D"]:
            ans = "No"
    else:
        if not S[i] in ["L", "U", "D"]:
            ans = "No"

print(ans)


Measured memory_bytes: 2940
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
using namespace std;
using ll = long long;
vector<vector<pair<ll,ll>>> v(100010);
vector<ll> dist(100010);
void dfs(ll cur, ll par,ll point=0){
    dist[cur] = point;
    // cout<<"cur:"<<cur<<", par:"<<par<<endl;
    for(ll i=0;i<v[cur].size();i++){
        ll next = v[cur][i].first;
        ll next_point = v[cur][i].second+point;
        // cout<<"next:"<<next<<endl;
        if(next!=par){
            dfs(next,cur,next_point);
        }
    }
    return;
}

int main(){
    long N;
    cin>>N;
    
    for(ll i=0;i<N-1;i++){
        ll a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        v[a].push_back(make_pair(b,c));
        v[b].push_back(make_pair(a,c));
    }
    
    ll Q,K;
    cin>>Q>>K;
    K--;
    ll x[Q],y[Q];
    for(ll i=0;i<Q;i++){
        ll _x,_y;
        cin>>_x>>_y;
        _x--;_y--;
        x[i] = _x;
        y[i] = _y;
    }
    dfs(K,-7,0);
    for(ll i=0;i<Q;i++){
        cout<<dist[x[i]]+dist[y[i]]<<"\n";
    }




}


Measured memory_bytes: 15872
#include <iostream>
#include <stdio.h>
using namespace std;

int main(){
    int n = 0, m = 0;
    cin >> n >> m;
    int A[100][100] = {};
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            cin >> A[i][j];
        }
    }
    int B[100] = {};
    for (int k = 0; k < m; k++){
        cin >> B[k];
    }
    int x = 0;
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            x += A[i][j] * B[j];
        }
        cout << x << endl;
        x = 0;
    }
}


Measured memory_bytes: 3156
n,k = map(int, input().split())
r,s,p = map(int, input().split())
t = input()

score = [0 for i in range(n)]

for i in range(n):
    if k<=i:
        if t[i]==t[i-k]:
            if score[i-k]!=0:
                continue
    if t[i] == 'p':
        score[i] = s
    elif t[i] == 'r':
        score[i] = p
    else:
        score[i] = r

print(sum(score))

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

int main(){
	string a, b, c;
	cin >> a >> b >> c;
	if (a.at(a.size() - 1) == b.at(0) && b.at(b.size() - 1) == c.at(0))
	{
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256
/*
Author: CNYALI_LK
LANG: C++
*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#define up(a,b,c) for (int a(b),end##a(c);a<=end##a;++a)
#define down(a,c,b) for (int a(b),end##a(c);a>=end##a;--a)
#define uup(a,c,b) for (int a(b),end##a(c);a<=end##a;++a)
#define udown(a,b,c) for (int a(b),end##a(c);a>=end##a;--a)
#define endl '\n'
using namespace std;
const double eps=1e-8;
const double PI=acos(-1.0);
struct inout{
	static const int ibufl=1<<25;
	static const int obufl=1<<25;
	char in_buf[ibufl],out_buf[obufl],*inf,*ouf;
	void init(){
		fread(in_buf,1,ibufl,stdin);
		inf=in_buf;
		ouf=out_buf;
	}
	inout& operator >>(int &a){
		int fh=1;
		while(!(isdigit(*inf)||*inf=='-'))++inf;
		if(*inf=='-')fh=-1,++inf;
		a=0;
		while(isdigit(*inf)){a=a*10+*inf-'0';++inf;}
		a*=fh;
		return *this;
	}
	inout& operator >>(char &a){
		while(*inf==' '||*inf=='\n')++inf;
		a=*inf;
		++inf;
		return *this;
	}
	inout& operator >>(char *a){
		while(*inf==' '||*inf=='\n')++inf;
		while(!(*inf==' '||*inf=='\n')){*a=*inf;++inf;++a;}
		*a='\0';
		return *this;
	}

	inout& operator >>(double &a){
		int fh=1;
		double s;
		while(!(isdigit(*inf)||*inf=='-'||*inf=='.'))++inf;
		if(*inf=='-')fh=-1,++inf;
		a=0;
		while(isdigit(*inf)){a=a*10+*inf-'0';++inf;}
		if(*inf=='.'){
			s=0.1;
			++inf;
			while(isdigit(*inf)){
				a+=s*(*inf-'0');
				++inf;
				s*=0.1;
			}
		}
		if(*inf=='E'||*inf=='e'){
			int ss;
			++inf;
			*this>>ss;
			if(ss>0){
				while(ss){
					--ss;
					a*=10;
				}
			}
			if(ss<0){
				while(ss){
					++ss;
					a/=10;
				}
			}
			
		}
		a*=fh;
		return *this;
	}
	void writeint(int x){
		if(x/10)writeint(x/10);
		*ouf=x%10+'0';
		++ouf;
	}
	inout& operator <<(int a){
		
		if(a<0){*ouf='-';++ouf;a=-a;}
		writeint(a);
		return *this;
	}
	static const int sz=7;
	inout& operator <<(char a){
		*ouf=a;++ouf;
		return *this;
	}
	inout& operator <<(char *a){
		while(*a){
			*ouf=*a;
			++ouf;
			++a;
		}
		return *this;
	}
	inout& operator <<(double a){
		if(a<-eps){*ouf='-';++ouf;a=-a;}
		writeint((int)a);
		a-=(int)a;
		*ouf='.';
		++ouf;
		up(i,1,sz){
			a=a*10;
			*ouf=(int)a+'0';
			++ouf;
			a-=(int)a;
		}
		return *this;
	}
	void out(){
		fwrite(out_buf,1,ouf-out_buf,stdout);	
	}
};
inout io;
int main(){
	int n;
	cin>>n;
	if(n%10==n/100)cout<<"Yes\n";
	else cout<<"No\n";

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


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

    vll ans(n + 1, 0);
    for (int i = n; i >= 1; i--) {
        ll cnt = 0;
        for (int k = 2; i * k <= n; k++) {
            cnt += ans[k * i];
        }
        if (cnt % 2 != a[i]) {
            ans[i] = 1;
        }
    }

    cout << accumulate(all(ans), 0) << endl;
    for (int i = 1; i <= n; i++) {
        if (ans[i] == 1) {
            cout << i << " ";
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3968
from sys import stdin
from collections import deque
from collections import Counter


def grid2adj(arr_grid,direction=4):
    def cand(i,j,direction):
        if direction == 4:
            return [[i-1,j],[i+1,j],[i,j-1],[i,j+1]]
        elif direction == 8:
            return [[i-1,j],[i+1,j],[i,j-1],[i,j+1],
                    [i-1,j-1],[i-1,j+1],[i+1,j-1],[i+1,j+1]]
        else:
            print('Error')
    
    M,N = len(arr_grid),len(arr_grid[0])
    arr_con = [[] for i in range(M*N)]
    for i in range(M):
        for j in range(N):
            v = i*N+j
            for _cand in cand(i,j,direction):
                if 0<=_cand[0]<M and 0<=_cand[1]<N:
                    next_v = _cand[0]*N+_cand[1]
                    arr_con[v].append(next_v)
    arr_val = sum(arr_grid,[])

    return arr_con, arr_val


class BFS():
    def __init__(self, con, val=None):
        # 隣接リスト表現
        self.con = con
        self.val = val
        self.N = len(self.con)
        # 始点からの距離
        self.dist = [-1]*self.N
        self.que = deque()

    def bfs(self, start_v):
        # 初期条件(0-indexed)
        self.dist[start_v] = 0
        self.que.append(start_v)

        while len(self.que)>0:
            v = self.que.popleft()
            for next_v in self.con[v]:
                if self.dist[next_v] != -1:
                    continue
                if self.val[next_v] == '#':
                    continue
                self.dist[next_v] = self.dist[v] + 1
                self.que.append(next_v)


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    H, W = list(map(int,_in[0].split(' ')))  # type:list(int)
    graph = []
    for i in range(H):
        _ = list(_in[i+1])  # type:list(str)
        graph.append(_)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    g_con, g_val = grid2adj(graph)
    bfs = BFS(g_con,g_val)

    cnt = 0
    bfs.bfs(0)
    if bfs.dist[-1] == -1:
        cnt = -1
    else:
        cnt = H*W-bfs.val.count('#')-(bfs.dist[-1]+1)
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)


Measured memory_bytes: 41456
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<ctime>
#include<cmath>
#include<vector>
#include<set>
#include<queue>
#include<deque>
#include<map>
#include<cstring>
#include<stack>
#include<cctype>
#include<cstdio>
#include<bitset>
#ifdef LOCAL
	#define enu(i,n) for(int i=0;i<n;i++)
	#define tri(x) x*(x+1)/2;
	#define sqrsum(x) x*(x+1)*(2*x+1)/6;
	#define sqrsum_range(a,b) sqrsum(b)-sqrsum(a-1);
#endif
#define FOR(i,a,b) for(int i=a,_b=b;i<_b;i++)
#define REP(i,a,b) FOR(i,a,b+1)
#define ll_max 9223372036854775807LL
#define ll_min -9223372036854775808LL
#define int_max 2147483647
#define int_min -2147483648
#define PI 3.14159265358979323846265
#define eps 0.00000001
#define elif else if
using namespace std;
void fast()
{
	cin.tie(NULL);
	cout.tie(NULL);
	ios_base::sync_with_stdio(false);
	return ;
}
bool isprime(int x)
{
	if(x<2)
		return false;
	for(int i=2;i<=sqrt(x);i++)
		if(x%i==0)
			return false;
	return true;
}
int GCD(int a,int b)
{
	return (b?GCD(b,a%b):a);
}
struct Tm
{
	int h,m,s;
	bool add()
	{
		s++;
		if(s==60)
			m++,
			s=0;
		if(m==60)
			h++,
			m=0;
		return (h<100);
	}
	void print()
	{
		printf("%02d:%02d:%02d",h,m,s);
		return ;
	}
	void println()
	{
		print();
		puts("");
	}
};
int A[200200];
int main()
{
	int a;
	cin>>a;
	for(int i=0;i<a;i++)
		cin>>A[i];
	int x=max_element(A,A+a)-A;
	sort(A,A+a);
	for(int i=0;i<a;i++)
		if(i==x)
			cout<<A[a-2]<<endl;
		else	cout<<A[a-1]<<endl;
	return 0;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define OUT(x) cout << (x) << endl;
#define OUTA(a, n) \
    REP(i, n) { cout << (a[i]) << (i == n - 1 ? "\n" : " "); }
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) \
    SORT(a);     \
    reverse(a.begin(), a.end())
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

ll N;
vi P;

int main()
{
    cin >> N;
    P = vi(N);
    REP(i, N)
    {
        cin >> P[i];
    }

    ll ans = 0;
    ll x = INF;
    REP(i, N)
    {
        if (P[i] < x)
        {
            ++ans;
            x = P[i];
        }
    }
    OUT(ans);
}


Measured memory_bytes: 1792
#include<stdio.h>

int main(void) {
        int m, f, r;

        while(1) {
                scanf("%d %d %d", &m, &f, &r);
                if(m==-1 && f==-1 && r==-1)      break;
                if(m==-1 || f==-1)              printf("F\n");
                else if((m+f)>=80)              printf("A\n");
                else if((m+f)>=65)              printf("B\n");
                else if((m+f)>=50)              printf("C\n");
                else if((m+f)>=30 && r>=50)     printf("C\n");
                else if((m+f)>=30)              printf("D\n");
                else                            printf("F\n");
        }
        return 0;
}

Measured memory_bytes: 584
import java.util.ArrayList;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

class Main {

	public static void main(String[] args) {
		Set<Long> set = new TreeSet<Long>();
		Set<Long> ans = new TreeSet<Long>();
		try (Scanner sc = new Scanner(System.in)){
			int times = sc.nextInt();
			for (int i=0; i<times; i++) {
				Long l = sc.nextLong();
				boolean check = set.add(l);
				if (!check) ans.add(l);  //重複した場合ansに追加
			}
			times = sc.nextInt();
			for (int i=0; i<times; i++) {
				Long l = sc.nextLong();
				boolean check = set.add(l);
				if (!check) ans.add(l);  //重複した場合ansに追加
			}
			ArrayList<Long>  a = new ArrayList<Long>(ans);
			for (int i=0; i<a.size(); i++) System.out.println(a.get(i));
		}
	}
}


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

#define ll long long
#define pb push_back
#define ep emplace_back
#define st first
#define sc second

using namespace std;

const ll mod = 1e9 + 7;
const int e = 1e6 + 69;
const int base = 311;

// dung inverse module de tinh kCn
// 65
// cach tao hoan vi tu n so : n*(n+1)/2;

int n;

struct kien
{
    ll x, y, id;
};

kien a[e], b[e];

bool lf(const kien &p, const kien &q)
{
    return p.x < q.x;
}

bool lf1(const kien &p, const kien &q)
{
    return p.y < q.y;
}

int main()
{
    deque<ll>s;
    cin >> n;
    for(int i=1; i<=n; i++)
    {
        ll x;
        cin >> x;
        if(i % 2 == 1)
        {
            s.push_front(x);
        }
        else
        {
            s.push_back(x);
        }
    }
    if(n % 2 == 0) reverse(s.begin(), s.end());
    for(auto j : s) cout << j <<" ";
}


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

using namespace std;
typedef vector<int> vi;

int main()
{
    //freopen("inp.txt","r",stdin);
    //freopen("outp.txt","w",stdout);
    int n,k=-1;
    cin>>n;
    int a[n],b[n];
    for(int i=0;i<n; i++)
    {
        cin>>a[i];
        k=max(k,a[i]);
    }
    /*for(int i=0;i<=k;i++)
        c[i]=0;

    for(int j=1;j<=n;j++)
        c[a[j]]=c[a[j]]+1;

    for(int i=1;i<=k;i++)
        c[i]=c[i]+c[i-1];

    for(int j=n;j>=1;j--)
    {
        b[c[a[j]]]=a[j];
        c[a[j]]=c[a[j]]-1;
    }*/
    sort(a,a+n);

    for(int i=0;i<n;i++)
    {
        if(i==0)
            cout<<a[i];
        else
            cout<<" "<<a[i];
    }
    cout<<"\n";
    return 0;
}



Measured memory_bytes: 10912
#include<bits/stdc++.h>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;
#define rep(i,n) for(UL i=0; i<(n); i++)

const ULL M=1000000007;

ULL MSign(LL a){
 if(a<0) return M-((-a-1)%M)-1;
 return a%M;
}

int main() {
 UL N,K; scanf("%u%u",&N,&K);
 deque<LL> A[2];
 rep(i,N){
  LL a; scanf("%lld",&a);
  A[(a<=0)?0:1].push_back(a);
 }
 sort(A[0].begin(),A[0].end());
 sort(A[1].begin(),A[1].end());
 ULL ans=1;
 if(A[1].empty()){
  if(K%2==1) reverse(A[0].begin(),A[0].end());
  rep(k,K) ans=ans*MSign(A[0][k])%M;
 }
 else if(N==K){
  rep(i,2) for(LL a:A[i]) ans=ans*MSign(a)%M;
 }
 else{
  if(K%2==1){ ans=MSign(A[1].back()); N--; K--; A[1].pop_back(); }
  reverse(A[1].begin(),A[1].end());
  if(A[0].size()%2==1){ N--; A[0].pop_back(); }
  if(A[1].size()%2==1){ N--; A[1].pop_back(); }
  rep(i,A[0].size()){ A[0].push_back(A[0][0]*A[0][1]); rep(j,2)A[0].pop_front(); }
  rep(i,A[1].size()){ A[1].push_back(A[1][0]*A[1][1]); rep(j,2)A[1].pop_front(); }
  rep(k,K/2){
   UL c=0;
   if(A[0].empty()) c=1;
   if(A[0].size() && A[1].size()) if(A[0][0]<A[1][0]) c=1;
   ans = ans*(MSign(A[c][0]))%M;
   A[c].pop_front();
  }
 }
 printf("%llu\n",ans);
 return 0;
}



Measured memory_bytes: 5488
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int maxx = 1e5;

int main()
{
	int n;
	cin >> n;
	cout << pow(n, 3) << '\n';

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
//printf("%.10f\n", N);
/*
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
int main(){
    string S;
    cin >> S;
    ll N = 0,W = 0,SO = 0,E = 0;
    ll s = S.size();
    rep(i,s){
        if(S[i] == 'N')N++;
        else if(S[i] == 'W')W++;
        else if(S[i] == 'E')E++;
        else SO++;
    }
    if(N && W && SO && E)cout << "Yes" << endl;
    else if(N && SO && !W && !E)cout << "Yes" << endl;
    else if(!N && !SO && W && E)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef vector<ll> vi;
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
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; }

int main(){
  string a, b, c;
  cin >> a >> b >> c;
  cout << 'A' << b[0] << 'C' << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
typedef long long ll;
ll p[maxn], l[maxn], a[maxn];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	p[1]=a[1], l[n]=a[n];
	ll ans=0;
	for(int i=2;i<=n;i++)
	{
		p[i]=__gcd(p[i-1], a[i]);
//		l[n-i+1]=__gcd(l[n-i+2], a[n-i+1]);
	}
	for(int i=n-1;i>=1;i--)
	{
		l[i]=__gcd(l[i+1], a[i]);
	}
	for(int i=2;i<n;i++)
	{
		ans = max(ans, __gcd(p[i-1], l[i+1]));
	}
	cout<<max(ans, max(l[2], p[n-1]))<<endl;
}

Measured memory_bytes: 6056
n=int(input())
s=input()
ans=s.count("R")*s.count("G")*s.count("B")
for i in range(n):
  for j in range(i,n):
    if 2*j-i>=n:
      break
    else:
      if s[i]!=s[j]!=s[2*j-i]!=s[i]:
        ans-=1
print(ans)

Measured memory_bytes: 9188
#include <bits/stdc++.h>
#include <iostream>
#include <ctime>
using namespace std;
#define _LL long long
#define rep(i, n) for (_LL i = 0; i < (_LL)(n); i++)
#define vecrep(itr, v) for (auto itr = (v).begin(); itr != (v).end(); itr++)

_LL ans(_LL h)
{
    if( h == 1 ) return 1;
    return 2 * ans( h / 2) + 1;
}

int main()
{
    _LL h; cin >> h;
    cout << ans(h);    
}

Measured memory_bytes: 3624