akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (V)) cout <<x <<" " <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


int N;
vector<string> S;
vector<string> res;
vector<int> num(3, 0);
string t = "ABC";

void ope(int i,int n1,int n2){
  // n1を足してn2を弾く
  res[i] += t[n1];
  num[n1]++; num[n2]--;
}

int main() {
  cin >>N;
  rep(i, 3) cin >>num[i];
  S.assign(N, ""); rep(i, N) cin >>S[i];
  res.assign(N, "");
  rep(i, N){
    int n1,n2;
    n1 = S[i][0] == 'A' ? 0 : 1;
    n2 = S[i][1] == 'B' ? 1 : 2;
    if (num[n1] < num[n2]) ope(i,n1,n2);
    else if (num[n1] > num[n2]) ope(i,n2,n1);
    else{
      if (i == N-1) ope(i,n1,n2);
      else{
        int nn1 = S[i+1][0] == 'A' ? 0 : 1;
        int nn2 = S[i+1][1] == 'B' ? 1 : 2;
        if (n1 == nn1 && n2 == nn2) ope(i,n1,n2);
        else if (n1 == nn1 || n1 == nn2) ope(i,n1,n2);
        else ope(i,n2,n1);
      }
    }
    if (num[0] < 0 || num[1] < 0 || num[2] < 0){
      cout <<"No" <<endl; return 0;
    }
  }
  cout <<"Yes" <<endl;
  rep(i, N){
    cout <<res[i] <<endl;
  }
}

/*
*/

Measured memory_bytes: 9596
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int dx[]={0,-1,0,1};
const int dy[]={-1,0,1,0};
int main(){
    int n;
    while(cin>>n,n){
        char s,t,b;
        cin>>s>>t>>b;
        int dp[2][3][3];
        fill_n(**dp,18,0);
        s-='A';t-='A';b-='A';
        dp[0][s/3][s%3]=1;
        for(int k=0;k<n;k++){
            for(int i=0;i<3;i++){
                for(int j=0;j<3;j++){
                    for(int l=0;l<4;l++){
                        int ty=i+dy[l];
                        int tx=j+dx[l];
                        if(tx<0||tx>=3||ty<0||ty>=3||ty*3+tx==b){
                            dp[(k+1)&1][i][j]+=dp[k&1][i][j];
                        }
                        else dp[(k+1)&1][ty][tx]+=dp[k&1][i][j];
                    }
                    dp[k&1][i][j]=0;
                }
            }
        }
        int sum=0;
        for(int i=0;i<3;i++)
            for(int j=0;j<3;j++)
                sum+=dp[n&1][i][j];

        cout<<fixed<<(double)dp[n&1][t/3][t%3]/sum<<endl;
    }
    return 0;
}

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

using namespace std;
int main()

{
    int X, A, B;
		cin>>X>>A>>B;
 
		if (B-A<=0) {
        cout<<"delicious"<<endl;
		}
		else if (B-A<=X) {
			cout<<"safe"<<endl;;
		}
		else {
			cout<<"dangerous"<<endl;
		}
    
  return 0;
}


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

using namespace std;

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

    int n, sum_t = 0;

    cin >> n;
    vector<int> t(n);
    for (int i = 0; i < n; ++i) {
        cin >> t[i];
        sum_t += t[i];
    }

    int m, p, x;
    cin >> m;
    for (int i = 0; i < m; ++i) {
        cin >> p >> x;
        cout << sum_t - t[p - 1] + x << endl;
    }

    return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))

dp=[[0 for i in range(2)] for i in range(n+1)]
dp[0][0]=0
dp[0][1]=-10**9+1

for i in range(0,n):
    dp[i+1][0]=max(dp[i][0]+a[i] , dp[i][1]-a[i])
    dp[i+1][1]=max(dp[i][0]-a[i] , dp[i][1]+a[i])

print(dp[n][0])
#解説AC

Measured memory_bytes: 72736
#include <iostream>
#include <string>

using namespace std;

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

    for (int i; i<n.size(); i++) {
        if (n[i] == '1') n[i] = '9';
        else n[i] = '1';
    }
    
    cout << n << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int a, b,ans;
	cin >> a >> b;
	if (a<b){
		cout << "a < b"  ;
	}
	if (a>b){
		cout << "a > b"  ;
	}
	if (a == b){
		cout << "a == b"  ;
	}
	
	cout <<endl;
	cin >> ans;
}


Measured memory_bytes: 3108
n = int(input())
num = n

fct = []
b = 2
while b * b <= n:
    while n % b == 0:
        n //= b
        fct.append(b)
    b += 1
if n > 1:
    fct.append(n)

print(str(num) + ": " + ' '.join(str(f) for f in fct))



Measured memory_bytes: 5604
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define trav(x,a) for (const auto& x: a)
#define sz(x) (int)(x).size()
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int _i = 0; _i < (n); _i++) ni(a[_i])
#define nal(a, n) for (int _i = 0; _i < (n); _i++) nl(a[_i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
const int N = 1e6 + 5;
const double eps = 1e-9;
int a[N], fac[N];

int main() {
  fac[0] = 1;
  for (int i = 1; i < N; i++)
    fac[i] = fac[i-1] * 1ll * i % mod;
  int n; scanf("%d", &n);
  int ans = 1, lst = 1;
  for (int i = 1; i <= n; i++) {
    scanf("%d", a+i);
    a[i] = min(lst, a[i]);
    lst = a[i]+2;
  }
  stack<int> st;
  for (int i = 1; i <= n; i++) {
    st.push(i);
    if (a[i] < 2*sz(st)-1) {
      ans = ans * 1ll * sz(st) % mod;
      st.pop();
    }
  }
  ans = ans * 1ll * fac[sz(st)] % mod;
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 6784
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << "square1001" << endl;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<bool> s(n+1), g(n+1);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    if (a == 1) s[b] = true;
    if (b == n) g[a] = true;
  }
  bool ans = false;
  rep(i, n + 1) {
    if (s[i] && g[i]) ans = true;
  }
  if (ans) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 256
from fractions import gcd
def lcm(a,b):
    return a*b//gcd(a,b)
a,b,c,d = map(int,input().split())
a-=1
print((b-a)-(b//c+b//d-a//c-a//d-(b//lcm(c,d))+(a//lcm(c,d))))


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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int l, r, d;
    cin >> l >> r >> d;
    cout << (r/d-(l+d-1)/d+1) << endl;
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x) 
#define REP(i, n) for (int i = 0; i < n; ++i) 
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)

const int MOD = 1e9+7;

int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    int N; cin >> N;
    int c[] = {0,0,0}, ans = 1;
    FOR(i,0,N-1){
        int A; cin >> A;
        int x = 0;
        FOR(j,0,2) if (c[j] == A) ++x;
        ans = (ll)ans * x % MOD;
        FOR(j,0,2) if (c[j] == A) { ++c[j]; break; }
    }

    cout << ans;
}



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

#define ll long long
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007

using namespace std;

//------------------------------------------------------------------------------
ll power(ll a,ll n)
{
          ll result=1;
          while(n>0)
          {
               if(n&1)
                    result=result*a;
               a=a*a;
               n=n>>1;
          }
          return result;
}
ll lcm(ll a,ll b)
{
          return ((a*b)/__gcd(a,b));
}
ll __ceil(ll a,ll b)
{
            return (a+b-1)/b;
}
bool ispow2(ll n)
{
          return (ceil(log2(n))==floor(log2(n)));
}
bool isprime(ll n)
{
          if(n==1)
               return false;
          else if(n==2)
               return true;
          else
          {
               for(ll i=2;i*i<=n;++i)
               {
                    if(n%i==0)
                         return false;
               }
               return true;
          }
}

ll ncr(ll n,ll r)
{
    if(r > n - r)
          r = n - r;
    ll ans = 1;
    ll i;

    for(i = 1; i <= r; i++)
     {
        ans *= n - r + i;
        ans /= i;
    }

    return ans;
}
void sieve(int n)
{
    // Create a boolean array "prime[0..n]" and initialize
    // all entries it as true. A value in prime[i] will
    // finally be false if i is Not a prime, else true.
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
     prime[1]=false;
     prime[0]=false;
    for (int p=2; p*p<=n; p++)
    {
        // If prime[p] is not changed, then it is a prime
        if (prime[p] == true)
        {
            // Update all multiples of p greater than or
            // equal to the square of it
            // numbers which are multiple of p and are
            // less than p^2 are already been marked.
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }

    // Print all prime numbers
    for (int p=2; p<=n; p++)
       if (prime[p])
          cout<<p<<" ";
}
//------------------------------------------------------------------------------


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

          int t=1;
          //cin>>t;
          while(t--)
          {
                    int a;
                    cin>>a;
                    for(int i=1;i<=a;++i)
                         cout<<"ACL";
          }
          return 0;
}


Measured memory_bytes: 3584
#!/usr/bin/env python3
import fractions
def solve(a, b, c, d):
    if a < b:
        return False
    if d < b:
        return False
    if b <= c:
        return True
    assert c < b <= min(a, d)
    g = fractions.gcd(b, d)
    return b - g + a % g <= c

t = int(input())
for _ in range(t):
    a, b, c, d = map(int, input().split())
    ans = solve(a, b, c, d)
    print(['No', 'Yes'][ans])


Measured memory_bytes: 5216
def d_multiple_of_2019():
    from collections import Counter
    S = [int(ch) for ch in input()]

    p = 2019  # ABC158-E のソースコードを流用するため
    s = S[::-1]
    u = [0] * len(S)
    u[0] = s[0] % p

    power = 1
    for i in range(1, len(S)):
        power *= 10
        power %= p
        u[i] = u[i - 1] + power * s[i]
        u[i] %= p
    count = Counter(u)
    return sum(v * (v - 1) // 2 for v in count.values()) + count[0]

print(d_multiple_of_2019())

Measured memory_bytes: 19716
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long n,ans=0,mod=1000000007;
  bool b=true;
  cin >> n;
  vector<long> t(n),a(n),max(n);
  vector<bool> ika(n,true);
  for(long i=0;i<n;i++) cin >> t[i];
  for(long i=0;i<n;i++) cin >> a[i];
  
  max[0]=t[0];
  ika[0]=false;
  for(long i=1;i<n;i++) {
    max[i]=t[i];
    if(t[i-1]!=t[i]) ika[i]=false;
  }
  
  if(ika[n-1]) {
    if(max[n-1]<a[n-1]) b=false;
    else {
      max[n-1]=a[n-1];
      ika[n-1]=false;
    }
  } else {
    if(max[n-1]!=a[n-1]) b=false;
  }
  for(long i=n-2;i>=0;i--) {
    if(a[i]!=a[i+1]) {
      if(ika[i]) {
        if(max[i]<a[i]) b=false;
        else {
          max[i]=a[i];
          ika[i]=false;
        }
      } else {
        if(max[i]!=a[i]) b=false;
      }
    } else {
      if(ika[i]) max[i]=min(max[i],a[i]);
      else if(a[i]<max[i]) b=false;
    }
  }
  
  if(b) {
    ans=1;
    for(long i=0;i<n;i++) {
      if(ika[i]) ans=ans*max[i]%mod;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 5624
n, m = map(int, input().split())

abl = []
for _ in range(n):
    ab = list(map(int, input().split()))
    abl.append(ab)

cdl = []
for _ in range(m):
    cd = list(map(int, input().split()))
    cdl.append(cd)

ansl = [0 for _ in range(n)]
for i, ab in enumerate(abl):
    ans = 10**10
    for j, cd in enumerate(cdl):
        if abs(ab[0]-cd[0]) + abs(ab[1]-cd[1]) < ans:
            ansl[i] = j
            ans = abs(ab[0]-cd[0]) + abs(ab[1]-cd[1])

for ans in ansl:
    print(ans+1)


Measured memory_bytes: 3064
import scala.io.{StdIn => in}

object Main extends App {
  val Array(n, t) = in.readLine.split(" ").map(_.toInt);

  val res = Iterator.continually(in.readLine)
    .take(n)
    .map(_.split(" ").map(_.toInt))
    .filter(a => a(1) <= t)
    .toArray

  val ans = if(res.nonEmpty) res.sortBy(_(0)).head(0) else "TLE"
  println(ans)
}

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

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

    string S;
    map<string, int> mp;
    for (int i = 0; i < N; i++) {
        cin >> S;
        mp[S] = 1;
    }

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

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = (int)(n)-1; i >=0; i--)

using ll = long long;

int main(){
  int n;
  cin >> n;
  map<ll,ll> m;
  rep(i,n){
    ll tmp;
    cin >> tmp;
    if(m.count(tmp))m[tmp]++;
    else m[tmp]=1;
  }
  ll ans = 0;
  for(auto p : m){
    ll k = p.first;
    ll v = p.second;
    if(v>k)ans+=(v-k);
    else if(v<k)ans+=v;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 6272
# include <bits/stdc++.h>
# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

// Did you miss me ?

# define gc          getchar
# define LL          long long
# define pb          push_back
# define mp          make_pair
# define vi          vector<int>
# define vll         vector<LL>
# define pii         pair<int,int>
# define all(v)      v.begin(),v.end()

const int MOD = 1000000007;
const int MAXN = 1e5 + 5;
const int INF = 1e9;
const int LN = 18;
const double PI = 3.14159265359;

template<class T> void in(T &x) { register T c=gc();x=0;T neg=0;for(;((c<48||c>57)&&c!='-');c=gc());if(c=='-'){neg=1;c=gc();}for(;c>47&&c<58;c=gc()){x=(x<<1)+(x<<3)+c-48;}if(neg)x=-x;}
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
LL power(LL a,LL b,LL m){ if(b==0) return 1; if(b==1) return a%m; LL t=power(a,b/2,m); t=(t*t)%m; if(b&1)t=(t*a)%m; return t;}
LL lcm(LL a, LL b) { LL ret = a*b; ret /= __gcd(a,b); return ret;}
LL nC2(LL n) {LL ret = n*(n-1)/2; return ret;}

vector<int> primes;
void sieve(int n)
{
	bool isPrime[n + 1];
	memset(isPrime, true, sizeof(isPrime));
	isPrime[0] = isPrime[1] = false;
	for(int i = 2; i * i <= n; i++) {
		if (isPrime[i]) {
			for (int j = 2 * i; j <= n; j += i)
			 	isPrime[j] = false;
		}
	}
	for (int i = 2; i <= n; i++)
		if (isPrime[i])
			primes.push_back(i);
}


int main() {
	LL n,a,b;
	cin>>n>>a>>b;
	if(n<2)
	{
		if(n==1 && a!=b)
			cout<<"0";
		else
			cout<<"1";

	}
	else if (a>b)
		cout<<"0";
	else
	{
		LL mx=a+(n-1)*b;
		LL mn=b+(n-1)*a;
		cout<<mx-mn+1;
	}
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct {
	int id;
	int syozoku;
	int solved;
	int penalty;
} team_t;

int qsort_comp(const void* x,const void* y) {
	const team_t* a=(const team_t*)x;
	const team_t* b=(const team_t*)y;
	if((a->solved)<(b->solved))return 1;
	if((a->solved)>(b->solved))return -1;
	if((a->penalty)>(b->penalty))return 1;
	if((a->penalty)<(b->penalty))return -1;
	if((a->id)>(b->id))return 1;
	if((a->id)<(b->id))return -1;
	return 0;
}


int chosen[1001];
int team_num;
team_t teams[300];

int main(void) {
	int i;
	int chosen_num;
	while(1) {
		scanf("%d",&team_num);
		if(team_num==0)break;
		for(i=0;i<team_num;i++) {
			scanf("%d%d%d%d",
				&teams[i].id,&teams[i].syozoku,
				&teams[i].solved,&teams[i].penalty);
		}
		qsort(teams,team_num,sizeof(team_t),qsort_comp);
		memset(chosen,0,sizeof(chosen));
		for(i=0,chosen_num=0;i<team_num;i++) {
			if(chosen_num<10) {
				if(chosen[teams[i].syozoku]<3) {
					printf("%d\n",teams[i].id);
					chosen_num++;
					chosen[teams[i].syozoku]++;
				}
			} else if(chosen_num<20) {
				if(chosen[teams[i].syozoku]<2) {
					printf("%d\n",teams[i].id);
					chosen_num++;
					chosen[teams[i].syozoku]++;
				}
			}if(chosen_num<26) {
				if(chosen[teams[i].syozoku]==0) {
					printf("%d\n",teams[i].id);
					chosen_num++;
					chosen[teams[i].syozoku]++;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

typedef long long ll;


int main(){

	int N;
	cin >> N;
	std::vector<int> B(N-1);
	std::vector<ll> A(N);

	for (int i = 0; i < N-1; i++)
	{
		cin >> B[i];
	}
	A[0] = B[0];
	A[N-1] = B[N-2];

	for (int i = 1; i < N-1; i++)
	{
		A[i] = min(B[i-1],B[i]);
	}
	int sum = 0;
	for (int i = 0; i < N; i++)
	{
		sum += A[i];
	}
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    vector<int> n(6);
    vector<int> m(4);
    for(int i=0; i<6; i++){
        cin>>n.at(i);
        for(int j=1; j<=4; j++){
            if (n.at(i)==j) {
                m.at(j-1)++;
            }
        }
    }
    sort(m.begin(), m.end());
    if(m.at(2) == m.at(3))
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int func(int a,int b)
{
	return (a+b)*(b-a+1)/2;
}


int main(void)
{
	int a,i,j,ret;
	while(1){
		ret = 0;
		scanf("%d",&a);
		if(a == 0)
			break;
		for(i = 1;i <= 500;i++){
			for(j = 1;j <= 500;j++){
				if(i < j && func(i,j) == a)
					ret++;
			}
		}
		printf("%d\n",ret);
	}
	return 0;
}

Measured memory_bytes: 600
// Math = ♥️

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ld long double
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
#define pq priority_queue
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define ordered_set                            \
    tree<ll, null_type, less<ll>, rb_tree_tag, \
         tree_order_statistics_node_update>

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

    ll n;
    cin >> n;

    vi arr(n);
    map<ll, ll> m;
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
        m[arr[i]]++;
    }

    ll ans = 0;
    for (auto it : m) {
        ans += ((it.ss) * (it.ss - 1)) / 2;
    }

    for (auto it : arr) {
        ans -= ((m[it]) * (m[it] - 1)) / 2;
        m[it]--;
        ans += ((m[it]) * (m[it] - 1)) / 2;
        cout << ans << "\n";
        ans -= ((m[it]) * (m[it] - 1)) / 2;
        m[it]++;
        ans += ((m[it]) * (m[it] - 1)) / 2;
    }
}


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

#define FST first
#define SCD second
#define MODP 1000000007

typedef long long LL;
typedef pair<int, int> PA;

int cmp(PA x, PA y) {
    return x.SCD < y.SCD;
}

int main() {
#ifdef FDB
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    int n, m, k;
    cin>>n>>k>>m;
    int d = 1000000000;
    if (m==d) d-=1;
    for (int i=0;i<k;++i) printf("%d ", m);
    for (int i=k;i<n;++i) printf("%d ", d);
    return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U& u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U& u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
template<class T> bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T & a, const T & b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vll A(N);
	ll absmin = 1e9 + 5;
	ll sum = 0;
	int minus = 0;
	REP(i, N) {
		cin >> A[i];
		sum += abs(A[i]);
		if (A[i] < 0)minus++;
		chmin(absmin, abs(A[i]));
	}
	if (minus % 2) {
		cout << sum - 2 * absmin << endl;
	}
	else {
		cout << sum << endl;
	}
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
using namespace std;

typedef long long ll;
typedef double db;
typedef long double ldb;

template<class T> inline void checkmin(T &a,const T &b){if(b<a) a=b;}
template<class T> inline void checkmax(T &a,const T &b){if(b>a) a=b;}

const int inf=1e9+10;
const int maxn=2e5+10;

int dp[maxn],n,a[maxn];
vector <int> g[maxn];
vector <pair<int,int> > v;
int tree[maxn*4],pos[maxn],l[maxn],ans[maxn];

void update(int x,int l,int r,int pos,int val){
	if(l==r){
		tree[x]=val;
		return;
	}
	int mid=(l+r)>>1;
	if(pos<=mid) update(x<<1,l,mid,pos,val);
	else update(x<<1|1,mid+1,r,pos,val);
	tree[x]=max(tree[x<<1],tree[x<<1|1]);
}

int getval(int x,int l,int r,int cl,int cr){
	if(r<cl||l>cr) return 0ll;
	if(cl<=l&&r<=cr) return tree[x];
	int mid=(l+r)>>1;
	int val1=getval(x<<1,l,mid,cl,cr);
	int val2=getval(x<<1|1,mid+1,r,cl,cr);
	return max(val1,val2);
}

void dfs(int x,int fa){
	if(fa!=-1){
		if(l[x]<0){
			dp[x]=1;
		}
		else{
			int mx=getval(1,0,n-1,0,l[x]);
			dp[x]=mx+1;
		}
	}
	update(1,0,n-1,pos[x],dp[x]);
	ans[x]=getval(1,0,n-1,0,n-1);
	for(int i=0;i<g[x].size();i++){
		int to=g[x][i];
		if(to==fa) continue;
		dfs(to,x);
	}
	update(1,0,n-1,pos[x],0);
}

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d",&a[i]);
	for(int i=0;i<n-1;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		u--; v--;
		g[u].pb(v);
		g[v].pb(u);
	}
	for(int i=0;i<n;i++) v.pb(mp(a[i],i));
	sort(v.begin(),v.end());
	int lst=-1;
	for(int i=0;i<v.size();i++){
		pos[v[i].snd]=i;
		l[v[i].snd]=lst;
		if(i+1<n&&v[i].fst!=v[i+1].fst) lst=i;
	}
	dp[0]=1; ans[0]=1;
	update(1,0,n-1,pos[0],dp[0]);
	dfs(0,-1);
	for(int i=0;i<n;i++) printf("%d\n",ans[i]);
	return 0;
}


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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n;
	cin >> n;
	
	while(n > 0){
		int a, b, c;
		cin >> a >> b >> c;
		if(a * a + b * b == c * c || b * b + c * c == a * a ||
		  a * a + c * c == b * b)
			cout << "YES";
		else
			cout << "NO";
		cout << endl;
		
		-- n;
	}
	
	return 0;
}

Measured memory_bytes: 1184
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main(void)
{
	int n,i,j,a,k,x,y;
	x=100000000;
	cin>>n>>k;
	y=0;
	j=n;
	for(i=0;i<n;i++){
		y=y*2;
		if(i==0) y=1;
		a=y;
		y=y+k*j;
		j=j-1;
//		cout<<y<<endl;
		if(y<x && y>=0){
			x=y;
		}
		y=a;
	}
	y=1;
	for(i=0;i<n;i++){
		y=y*2;
	}
	if(y<x && y>=0){
		x=y;
	}
	cout<<x<<endl;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
dp=[1000]*(n+1) #dp[i]:=i日目の取引が終わった時の最大値
for i in range(n):
    for j in range(i):
        dp[i]=max(dp[i],a[i] * (dp[j]//a[j]) + dp[j]%a[j])
    dp[i]=max(dp[i],dp[i-1])
print(dp[n-1])

Measured memory_bytes: 64624
using System;
					
public class Program
{
	public static void Main()
	{
		var input = Console.ReadLine();
		var split1 = input.Split(' ');
		var count = int.Parse(split1[0]);
		var cap = int.Parse(split1[1]);
		
		int current = 0;
		int result = 1;
		int target = 0;
		
		var split = Console.ReadLine().Split(' ');
		
		foreach(var tgt in split){
			target = int.Parse(tgt);
			current += target;
			if(current > cap){
				break;	
			}
			result++;
			
		}
		
		
		Console.WriteLine(result);
		
		//nsole.WriteLine("Hello World");
	}
}

Measured memory_bytes: 11092
#!/usr/bin/env ruby
# require 'pry'

# dpテンプレ
# 最小化
# dp = Hash.new{ Float::INFINITY }
# dp[i] = [dp[i], dp[i-1] + hoge].min
# dp[0] = 0
# 最大化
# dp = Hash.new{ 0 }
# dp[i] = [dp[i], dp[i-1] + hoge].max
# dp[0] = 0

a,v = gets.chomp.split(" ").map(&:to_i)
b,w = gets.chomp.split(" ").map(&:to_i)
t = gets.to_i

if w >= v
  puts 'NO'
elsif ((a-b).abs - (v-w) * t) <= 0
  puts 'YES'
else
  puts 'NO'
end


Measured memory_bytes: 14312
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

signed main()
{
	IO_OP;
	
	string s;
	cin >> s;
	int ans = 0;
	for(int i=0;i<s.size()/2;i++)
		ans += s[i] != s[(int)s.size()-1-i];
	cout << ans << endl;	
	
}





Measured memory_bytes: 256
import java.util.concurrent.LinkedBlockingDeque

fun intList() = readLine()?.split(" ")?.map(String::toInt) ?: TODO()
fun main() {
    data class Coordinate(
        val i: Int,
        val costs: Int
    )
    val (h, w) = intList()
    val matrix = Array(10) { Array(10) { 0 } }
    repeat(10) { i ->
        intList().forEachIndexed { j, v ->
            matrix[i][j] = v
        }
    }
    val numbers = hashMapOf<Int, Int>()
    repeat(h) {
        intList().forEach {
            numbers[it] = numbers.getOrDefault(it, 0) + 1
        }
    }
    var magic = 0
    numbers.keys.forEach {
        if (it != 1 && it != -1) {
            val queue = LinkedBlockingDeque<Coordinate>()
            var minCost = matrix[it][1]
            queue.offer(
                Coordinate(
                    it, 0
                )
            )
            while (!queue.isEmpty()) {
                val c = queue.poll()
                matrix[c.i].forEachIndexed { index, v ->
                    if (v != 0) {
                        val cost = c.costs + v
                        if (minCost > cost) {
                            if (index == 1) {
                                minCost = cost
                            }
                            queue.offer(
                                Coordinate(index, cost)
                            )
                        }
                    }
                }
            }
            magic += minCost * numbers.getOrDefault(it, 0)
        }
    }
    println(magic.toString())
}

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


#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define pii pair<int,int>
#define pli pair<long long,int>
#define pil pair<int,long long>
#define ll long long
#define el '\n'

using namespace std;

const int N = 3e2 + 10;

int n;
ll ar[N];
ll cur;

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

    cin >> n;
    for (int i=1;i<=n;i++){
        cin >> ar[i];
        cur ^= ar[i];
    }
    cur = ((cur ^ ar[1]) ^ ar[2]);
    ll ans = 0;
    for (ll i=0;i<50;i++){
        ll bit = (1LL << i);
        if ((cur & bit) != ((ar[1] & bit) ^ (ar[2] & bit))){
            ll j;
            ll temp = (1LL << (i + 1)) - 1LL;
            ll res = (cur & temp);
            ll a = ar[1], b = ar[2];
            for (j=0;j<50;j++){
                ll bit2 = (1LL << j);
                if (a < bit2){
                    j = 50;
                    break;
                }
                if (res == (((a - bit2) ^ (b + bit2)) & temp)) break;
            }
            if (j >= 50){
                cout << -1 << el;
                return 0;
            }
            ll tambah = (1LL << j);
            ans += tambah;
            ar[1] -= tambah;
            ar[2] += tambah;
        }
        for (ll i=50;i>=0;i--){
            ll bit2 = (1LL << i);
            if (bit2 > ans) continue;
            if (cur == ((ar[1] + bit2) ^ (ar[2] - bit2))){
                ans -= bit2;
                ar[1] += bit2;
                ar[2] -= bit2;
            }
        }
    }
    if (ar[1] == 0){
        cout << -1 << el;
        return 0;
    }
    cout << ans << el;

    return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
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 (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

int main() {
    int n, k; cin >> n >> k;
    vector<P> ans;
    FOR(i, 1, n) ans.emplace_back(i, n);
    int tot = (n-1)*(n-2)/2; // (n-1)Cr *r=2
    debug(tot);
    if (k>tot) {
        cout << -1 << endl;
        return 0;
    }
    FOR(i, 1, n) {
        FOR(j, i+1, n) {
            if (tot==k) break;
            ans.emplace_back(i, j);
            tot--;
            debug(tot);
        }
        if (tot==k) break;
    }
    debug(tot);

    cout << sz(ans) << endl;
    for(const auto& p: ans) cout << p.fi << " " << p.se << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<iomanip>
using namespace std;
int N;
long double X[1<<17],Y[1<<17];
char D[1<<17];
long double calc(long double v)
{
	long double xm=1e18,xM=-1e18,ym=1e18,yM=-1e18;
	for(int i=0;i<N;i++)
	{
		xm=min(xm,v*(D[i]=='L'?-1:D[i]=='R')+X[i]);
		xM=max(xM,v*(D[i]=='L'?-1:D[i]=='R')+X[i]);
		ym=min(ym,v*(D[i]=='D'?-1:D[i]=='U')+Y[i]);
		yM=max(yM,v*(D[i]=='D'?-1:D[i]=='U')+Y[i]);
	}
	return(xM-xm)*(yM-ym);
}
main()
{
	cin>>N;
	for(int i=0;i<N;i++)cin>>X[i]>>Y[i]>>D[i];
	long double ans=calc(0);
	long double L=0,R=1e18;
	for(int i=0;i<300;i++)
	{
		long double x1=calc((L*2+R)/3);
		long double x2=calc((L+R*2)/3);
		if(x1<x2)R=(L+R*2)/3;
		else L=(L*2+R)/3;
		ans=min(ans,min(x1,x2));
	}
	cout<<fixed<<setprecision(16)<<ans<<endl;
}

Measured memory_bytes: 3968
#include <stdio.h>

#define MAX 100

int main(){
  int i,j;
  int n,u,k,v;
  int g[MAX][MAX];
  
  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      g[i][j]=0;
    }
  }
  
  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      g[u-1][v-1]=1;      
    }
  }

  for(i=0;i<n;i++){
    for(j=0;j<n-1;j++){
      printf("%d ",g[i][j]);
    }printf("%d\n",g[i][j]);
  }

  return 0;

}

Measured memory_bytes: 632
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
const int inf = 2147483646;
typedef long long LL;
int day[40]={31,28,31,30,31,30,31,31,30,31,30,31};
int n,t;
int main() {
    int a,b,c,d;
    cin>>a>>b;
    cin>>c>>d;
    if (day[a-1] == b) cout<<1<<endl;
    else cout<<0<<endl;
    //cin>>c>>d;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In,' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            var M = cin.ReadInt;

            var Lmax = 0;
            var Rmin = N;

            for(var i=0;i<M;i++){
                var L = cin.ReadInt;
                var R = cin.ReadInt;

                if(L > Lmax) Lmax = L;
                if(R < Rmin) Rmin = R;
            }

            WriteLine(Lmax <= Rmin ? Rmin - Lmax + 1 : 0);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream,char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }

        public string Read
        {
            get
            {
                if(inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for(int i = 0;i < tmp.Length;i++)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }

        
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }

}


Measured memory_bytes: 15420
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  ll n;
  cin >> n;
  ll ans=1;
  ll a=n-1;
  for(ll i=2;i*i<=a;i++){
    if(a%i==0){
      if((i*i)!=a){
          ans +=2;
        }
      else
        ans +=1;
    }
  }
  vl yakusu(2*sqrt(n)+5,INF);
  ll j=0;
  for(ll i=2;i*i<=n;i++){
    if(i*i!=n){
      if(n%i==0){
        yakusu[j]=i;
        yakusu[j+1]=n/i;
        j +=2;
      }
    }
    else if(n%i==0){
      yakusu[j]=i;
    }
  }
  if(n>2){
    ans++;
  }
  ll c=0;
  ll i=0;
  while(yakusu[i]!=INF){
    c=i;
    i++;
  }
  rep(i,c+1){
    ll m=n;
    ll k=yakusu[i];
    while(m>=k){
      if(m%k==0){
        m /=k;
      }
      else
        m=m%k;
      if(m==1){
        ans++;
      }
    }
  }
  cout << ans << endl;
}

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

int main() {

	while(1){
		int N;
		cin >> N;
		if(N == 0) break;
		int x[N], y[N], z[N];
		for(int i = 0; i < N; i++){
			cin >> x[i] >> y[i];
			z[i] = 0;
		}
/*
		for(int i = 0; i < N; i++){
			cout << x[i] << " " << y[i] << " " << z[i] << endl;
		}
*/

		int M;
		cin >> M;
		char d_temp;
		int d[M], l[M];
		for(int i = 0; i < M; i++){
			cin >> d_temp >> l[i];
			if(d_temp == 'N'){
				d[i] = 0;
			}else if(d_temp == 'E'){
				d[i] = 1;
			}else if(d_temp == 'S'){
				d[i] = 2;
			}else if(d_temp == 'W'){
				d[i] = 3;
			}
		}
/*
		for(int i = 0; i < M; i++){
			cout << d[i] << " " << l[i] << endl;
		}
*/

		int nowx = 10, nowy = 10;
		for(int i = 0; i < M; i++){
			for(int j = 0; j < l[i] ; j++){
				if(d[i] == 0){
					nowy++;
				}else if(d[i] == 1){
					nowx++;
				}else if(d[i] == 2){
					nowy--;
				}else if(d[i] == 3){
					nowx--;
				}
//				cout << nowx << " " << nowy << endl;
				for(int k = 0; k < N; k++){
					if(nowx == x[k] && nowy == y[k]) z[k] = 1;
				}
			}
		}
/*
		for(int i = 0; i < N; i++){
			cout << x[i] << " " << y[i] << " " << z[i] << endl;
		}
*/

		int result = 1;
		for(int i =0; i < N; i++){
			if(z[i] == 0) result = 0;
		}
		if(result){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		}
	}

	return 0;
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

/*
左から見ていったときの最大値と右から見ていったときの最大値を比較する

*/
int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n)
    {
        cin >> a[i];
    }
    vector<int> left(n + 1);
    vector<int> right(n + 1);
    left[0] = 0;
    right[0] = 0;
    rep(i, n)
    {
        left[i + 1] = max(left[i], a[i]);
    }

    reverse(a.begin(), a.end());
    rep(i, n)
    {
        right[i + 1] = max(right[i], a[i]);
    }

    rep(i, n)
    {
        cout << max(left[i], right[n - 1 - i]) << endl;
    }
    return 0;
}


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

int main()
{


        int x, y;

        cin >> x >> y;

        int group = 0;

        switch (x) {

                case 1:
                case 3:
                case 5:
                case 7:
                case 8:
                case 10:
                case 12:
                        group = 1;
                        break;
                case 4:
                case 6:
                case 9:
                case 11:
                        group = 2;
                        break;
                case 2:
                        group = 3;
                        break;
        }

        int b = 0;
        switch (y) {

                case 1:
                case 3:
                case 5:
                case 7:
                case 8:
                case 10:
                case 12:
                        b = 1;
                        break;
                case 4:
                case 6:
                case 9:
                case 11:
                        b = 2;
                        break;
                case 2:
                        b = 3;
                        break;
        }
        if (group == b) {
                cout << "Yes" << endl;
        }
        else {
                cout << "No" << endl;
        }







}


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

using ll = long long;
const ll MOD = 1e9 + 7;

int main() {
    string S;
    cin >> S;
    int A = S[0] - '0', B = S[1] - '0', C = S[2] - '0', D = S[3] - '0';
    if (A + B + C + D == 7) {
        cout << A << "+" << B << "+" << C << "+" << D << "=7\n";
    } else if (A + B + C - D == 7) {
        cout << A << "+" << B << "+" << C << "-" << D << "=7\n";
    } else if (A + B - C + D == 7) {
        cout << A << "+" << B << "-" << C << "+" << D << "=7\n";
    } else if (A + B - C - D == 7) {
        cout << A << "+" << B << "-" << C << "-" << D << "=7\n";
    } else if (A - B + C + D == 7) {
        cout << A << "-" << B << "+" << C << "+" << D << "=7\n";
    } else if (A - B + C - D == 7) {
        cout << A << "-" << B << "+" << C << "-" << D << "=7\n";
    } else if (A - B - C + D == 7) {
        cout << A << "-" << B << "-" << C << "+" << D << "=7\n";
    } else if (A - B - C - D == 7) {
        cout << A << "-" << B << "-" << C << "-" << D << "=7\n";
    }
}

Measured memory_bytes: 256
function Main(input){
  inputs=input.split("\n");
  takos=inputs[1].split(" ");
  sums=takos.map(x=>parseInt(x)).reduce((sum,value)=>sum+value);
  points=takos.map(value=>{
    sums-=value;
    return value*sums;
  });
  console.log(points.reduce((sum,value)=>sum+value));
}
Main(require('fs').readFileSync('/dev/stdin','utf8'));


Measured memory_bytes: 21192
#include <iostream>
#include <stdio.h>

using namespace std;

struct Dice{

	int u;	int w;	int s;	int e;	int n;	int d;
	
	Dice (int d1, int d2, int d3, int d4, int d5, int d6)
		{u = d1; s = d2; e = d3; w = d4; n = d5; d = d6;}
	
	Dice (int *num){
		u = num[0]; s = num[1]; e = num[2];
		w = num[3]; n = num[4]; d = num[5];}
	
	Dice ()
		{u = 1; s = 2; e = 3; w = 4; n = 5; d = 6;}

	void rotate(char *direction){
		int dam = 0;
		for (int i = 0; direction[i] != '\0'; i++){
			switch (direction[i]){
			case 'E':
				dam = e;
				e = u; u = w; w = d; d = dam;
				break;
			case 'N':
				dam = n;
				n = u; u = s; s = d; d = dam;
				break;
			case 'S':
				dam = s;
				s = u; u = n; n = d; d = dam;
				break;
			case 'W':
				dam = w;
				w = u; u = e; e = d; d = dam;
				break;
			case 'X'://???????????¢
				dam = w;
				w = s; s = e; e = n; n = dam;
				break;
			default:
				break;
			}
		}
	}	
	
	void display(char direction){
		switch (direction){
			case 'E': printf("%d\n",e); break;
			case 'N': printf("%d\n",n); break;
			case 'S': printf("%d\n",s); break;
			case 'W': printf("%d\n",w); break;
			case 'U': printf("%d\n",u); break;
			case 'D': printf("%d\n",d); break;
			default: break;
		}
	}
};


int main(){
	Dice d[101];
	int n;
	int num[6];
	cin >> n;
	for (int j = 0; j < n; j++){
		for (int i = 0; i < 6; i++) cin >> num[i];
		d[j] = num;
	}
	
	for (int i = 0; i < n; i++){
		for (int j = i + 1; j < n; j++){
			//????????§????????¨?????????
			int a = d[i].u;
			int b = d[i].s;
			bool flag = false;
			if (d[j].n == a) d[j].rotate("S");
			else if(d[j].e == a) d[j].rotate("W");
			else if(d[j].s == a) d[j].rotate("N");
			else if(d[j].w == a) d[j].rotate("E");
			else if(d[j].d == a) d[j].rotate("EE");
			else if(d[j].u == a) {;}
			//else flag = true;//????????°???????????¨????°?????????¨???No??????????????????
			for (int k = 0; k < 4; k++){
				if (d[j].s == b) {//1?????§????????????????????????????????????
					if ( d[j].u == d[i].u && d[j].n == d[i].n && d[j].e == d[i].e && d[j].s == d[i].s && d[j].w == d[i].w && d[j].d == d[i].d){
						cout << "No" << endl;
						return 0;
					}
				}
				if ( k == 3 && i == n - 2 && j == n - 1){
					cout << "Yes" << endl;
					return 0;;
				}
				d[j].rotate("X");
			}
		}
	}
	return 0;
}

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

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

    cout << n*(1+n)/2 << endl;

    return 0;
}

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

int main() {
  while(1){
    string s;
    cin >> s;
    if(s == "0")
    break;

    int sum = 0;
    for(int i = 0; i < s.size(); i++){
      sum += s[i] - '0';
    }
    cout << sum << endl;
  }
}



Measured memory_bytes: 3168
#include<bits/stdc++.h>
#include <iostream>
#include<cstdio>
#define endl '\n'
//typedef long long ll;
using namespace std;
int main()
{
	int n,i;
	cin>>n;
	vector<int> v(n);
	vector<int> w(n);
	//vector<ll>::iterator it;
	for(i = 0; i<n; i++){
		cin>>v[i];
	}
	//sort(w.begin(),w.end());
	//int max = w[n-1],min;
	for(i = 0; i<n; i++){
	w[v[i]-1] = i+1;
	}
	for(i = 0; i<n; i++)cout<<w[i]<<" ";
	
	return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#include<algorithm>
#define ll long long
#include<cmath>
#include<string>
#include<set>
#include<vector>
#define MOD 1000000007
#define loop(a,b) for(ll i=a;i<b;i++)
#define fast_ip ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;

int main(){

	string s;
	string t;
	cin>>s>>t;
	int cnt=0;
	for(int i=0;i<3;i++)
	{
		if(s[i]==t[i])
			cnt++;
	}
	cout<<cnt<<"\n";
    return 0;
}


Measured memory_bytes: 256