akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5,P=998244353,Gi=332748118;
 
#define PII pair<int,int>
inline int add(const int &x,const int &y){return x+y>P?x+y-P:x+y;}
inline int dec(const int &x,const int &y){return x-y<0?x-y+P:x-y;}
inline int mul(const int &x,const int &y){return 1LL*x*y>P?1LL*x*y%P:x*y;}
 
int ksm(int x,int y=P-2){
    int ans=1;
    for(;y;y>>=1,x=mul(x,x))
        if(y&1)ans=mul(ans,x);
    return ans;
}
 
int lim,r[N],a[N],b[N],o[N],l;
int n,h[N],m,p[N],ans,fac[N],inv[N];
vector<int>f[N];
void init(int len){
    lim=1,l=-1;
    while(lim<=len)lim<<=1,++l;
    for(int i=1;i<lim;i++)r[i]=(r[i>>1]>>1)|((i&1)<<l);
}
void NTT(int *A,int ty){
    for(int i=0;i<lim;i++)
        if(i<r[i])swap(A[i],A[r[i]]);
    for(int p=1;p<lim;p<<=1){
        int D=p<<1,wn=ksm(ty==1?3:Gi,(P-1)/D);
        o[0]=1;
        for(int i=1;i<p;i++)o[i]=mul(o[i-1],wn);
        for(int i=0;i<lim;i+=D){
            for(int j=0;j<p;j++){
                int x=A[i+j],y=mul(A[i+j+p],o[j]);
                A[i+j]=add(x,y),A[i+j+p]=dec(x,y);
            }
        }
    }
    if(ty==-1)
        for(int i=0,INV__=ksm(lim);i<lim;i++)
            A[i]=mul(A[i],INV__);
}
int C(int x,int y){
	return mul(fac[y],mul(inv[x],inv[y-x]));
}
int A(int x,int y){
	return mul(fac[y],inv[y-x]);
}
priority_queue<PII,vector<PII>,greater<PII> >Q;
signed main(){
    scanf("%d",&n),n*=2;
    for(int i=1;i<=n;i++)scanf("%d",&h[i]);
    sort(h+1,h+1+n);
    for(int i=1;i<=n;i++){
    	if(h[i]!=h[i-1])p[++m]=1;
    	else p[m]++;
	}
	fac[0]=1;
	for(int i=1;i<=n;i++)fac[i]=mul(fac[i-1],i);
	inv[n]=ksm(fac[n]);
	for(int i=n-1;~i;i--)inv[i]=mul(inv[i+1],i+1);
    for(int i=1;i<=m;i++){
    	for(int j=0;j<=(p[i]>>1);j++){
    		f[i].push_back(mul(mul(A(j,p[i]),C(j,p[i]-j)),ksm(ksm(2,j))));
		}
		Q.push(PII(f[i].size(),i));
	}
	while(Q.size()>1){
		int u=Q.top().second;
		Q.pop();
		int v=Q.top().second;
		Q.pop(); 
		int su=f[u].size(),sv=f[v].size();
		init(su+sv-2);
		for(int i=0;i<=lim;++i) a[i]=b[i]=0;
		for(int i=0;i<su;++i) a[i]=f[u][i];
		for(int i=0;i<sv;++i) b[i]=f[v][i];
		NTT(a,1),NTT(b,1);
		for(int i=0;i<lim;i++) a[i]=mul(a[i],b[i]);
		NTT(a,-1);
		++m;
		if(!Q.size()){
			for(int i=0;i<=su+sv-2;++i)
				ans=add(ans,mul(mul(ksm(P-1,i),a[i]),mul(A((n-2*i)>>1,n-2*i),ksm(ksm(2,(n-2*i)>>1)))));
			break;
		}
		for(int i=0;i<=su+sv-2;++i) f[m].push_back(a[i]);
		Q.push(PII(f[m].size(),m));
	}
	printf("%d\n",(ans+P)%P);
}

Measured memory_bytes: 35324
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
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 V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    int N,M,C; cin >> N >> M >> C;
    vector<int> B(M); for(auto& in:B) cin >> in;
    for(int i = 0; i < N;i++){
        int  T= C;
        for(int j = 0; j < M;j++){
            int A; cin >> A;
            T += A*B[j];
        }
        if(T > 0) res++;
    }
    return res;
}
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    //solve<ll>(0);
    cout << fixed << setprecision(12) << solve<ll>() << endl;
    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
vector<int> ckd;
vector<vector<int>> grh;
void dfs (int crr, int prt) {
  if (ckd[crr] == 2) return;
  ckd[crr] = 1;
  for (int nxt : grh[crr]) {
    if (ckd[nxt] == 1) {
      cout << "Yes" << '\n';
      exit(0);
    }
    dfs(nxt, crr);
  }
  ckd[crr] = 2;
}
int main() {
  int n, m;
  string s;
  cin >> n >> m >> s;
  grh.resize(2 * n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    if (s[a] == s[b]) {
      grh[a].push_back(b + n);
      grh[b].push_back(a + n);
    } else {
      grh[a + n].push_back(b);
      grh[b + n].push_back(a);
    }
  }
  ckd.resize(2 * n, 0);
  for (int i = 0; i < 2 * n; i++) {
    dfs(i, i);
  }
  cout << "No" << '\n';
  return 0;
}

Measured memory_bytes: 26244
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x;
  cin >> x;
  if(x == 0)
    cout << 0 << endl;
  else if(x%3 == 0)
    cout << 3 << endl;
  else
    cout << x%3 << endl;
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}


int main(){
  int k; cin >> k;
  int a = 7;
  for(int i = 1; i <= 100000000; ++i){
    a = a % k;
    if(a == 0){
      cout << i << endl;
      return 0;
    }
    a = (a * 10 + 7);
  }
  cout << -1 << endl;  
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
struct Edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<Edge>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reprep(i,j,w,h) rep(j,h)rep(i,w)
#define rrep(i,m, n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> a(n);rep(i,n)std::cin >> a[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<int>(n,a)));
typedef long long ll;
const int INF = 2000000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
typedef unsigned int uint;
int main(){
  int k,x;
  std::cin >> k>>x;
  for(int i=max(-1000000,x-k+1);i<=min(1000000,x+k-1);i++)std::cout << i << " ";
  std::cout << std::endl;
}

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

#define tarzan ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long 

int rr[] = {0, 1, 1, 1, 0, -1, -1, -1};
int cc[] = {1, 1, 0, -1, -1, -1, 0, 1};

const int mod = 1e9 + 7;
const int N = 300050;

signed main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    tarzan;
    int test = 1;
    //cin >> test;
    while(test--) {
        int x;
        cin >> x;
        cout << (1 ^ x);
    }
    return 0;
}


Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] lines = sc.nextLine().split(" ");
		int num1 = Integer.parseInt(lines[0]);
		int num2 = Integer.parseInt(lines[1]);
		String result;
		if(num1 < num2){
			result = "a < b";
		} else if(num1 > num2) {
			result = "a > b";
		} else {
			result = "a == b";
		}

		System.out.println(result);

	}
}

Measured memory_bytes: 26136
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <cmath>
#include <iterator>
#include <numeric>
#include <iomanip>
#define FI first
#define SE second
#define EB emplace_back
#define REP(i, n) for (ll i = 0; i < n; i++)
#define INF 1100000000
#define LLINF 1100000000000000000LL
#define Decimal fixed << setprecision(20)
#define ALL(c) c.begin(),c.end()
#define SHOWVEC(v, sz) for(int i = 0; i < sz; i++) cerr << v[i] << ' '; cerr << endl;
#define SHOWX(x) cerr << #x << ": " << x << endl;
#define SHOWP(p) cerr << "[" << p.first << ',' << p.second << "]";

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

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

vector<ll> make_divider(ll N) {
  vector<ll> ret;
  for (ll i = 1; i * i <= N; i++) {
    if (N % i == 0) {
      ll d1 = i, d2 = N / i;
      ret.push_back(d1);
      if (d1 != d2) ret.push_back(d2);
    }
  }
  return ret;
}

// 素因数分解 O(sqrt(n))
map<ll, ll> prime_factor(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n] = 1;
  return res;
}

int main()
{
  ll A, B;
  cin >> A >> B;

  map<ll, ll> mp(prime_factor(gcd(A, B)));
  cout << mp.size() + 1 << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        
      int[] a=new int[n];
      
      for(int i=1;i<=n;i++){
        int h=sc.nextInt();
        a[h-1]=i;
      }
      for(int b:a){
      	System.out.println(b);
      }
      
    }
}

Measured memory_bytes: 60712
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <float.h>

#pragma region 定義
#define i_cin(X) scanf("%d", &X)
#define i_cin2(X,Y) scanf("%d %d",&X,&Y)
#define i_cin3(X,Y,Z) scanf("%d %d %d",&X,&Y,&Z)
#define l_cin(X) scanf("%ld",&X)
#define f_cin(X) scanf("%f",&X)
#define l_cin2(X,Y) scanf("%ld %ld",&X,&Y)
#define s_cin(X) scanf("%s",&X)

#define  i_cout(X) printf("%d\n",X)
#define  f_cout(X) printf("%g\n",X)
#define  i_cout2(X,Y) printf("%d %d\n",X,Y)
#define  l_cout(X) printf("%ld\n",X)
#define  s_cout(X) printf("%s\n",X)
#define  ll_cout(X) printf("%lld\n",X)

typedef long long  ll;
#define rept(x, s, n) for (int x = s; x < n; x++)

#define Yes_RTN s_cout("Yes");return 0
#define No_RTN  s_cout("No");return 0
#define YES_RTN s_cout("YES");return 0
#define NO_RTN  s_cout("NO");return 0


int i_cins(int n, int* A);
int l_cins2(int n, long* A, long* B);
int s_dsort(const void* a, const void* b);
int s_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);

int s_asorts(const void* a, const void* b);

//昇順
int s_asorts(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int s_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}
int l_cins2(int n, long* a, long* b) {
	int i;
	rept(i, 0, n) {
		l_cin2(*(a + i), *(b + i));
	}
	return 0;
}
int i_cins(int n, int* a) {
	int i;
	for (i = 0; i < n; i++) {
		i_cin(*(a + i));
	}

	return 0;
}
int _gcd(int a, int b) {
	int r, tmp;
	if (a < b) { tmp = a; a = b; b = tmp; }
	r = a % b;
	while (r) {
		if (!r) break;
		a = b; b = r;
		r = a % b;
	}
	return(b);
}

long _max(long a, long b) {
	return a > b ? a : b;
}
long _min(long a, long b) {
	return a < b ? a : b;
}
int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}

#pragma endregion


#define A_RTN s_cout("Alice");return 0
#define B_RTN s_cout("Borys");return 0
#define D_RTN s_cout("Draw")return 0
int main(void) {
	int N, A, B, a, b;

	i_cin3(N, A, B);
	if ((B - A - 1) % 2) { A_RTN; }
	B_RTN;
	   
}



Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for (int i = 0; i < (n); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin >> n;
    vector<ll> a(n),b(n);
    ll sum=0,t=0;
    rep(i,n){
        cin >> a[i];
        sum+=a[i];
        if(i%2==0&&i!=n-1){
            t+=a[i]*2;
        }
    }
    b[n-1]=sum-t;
    for(int i=n-2;i>=0;i--){
        b[i]=a[i]*2-b[i+1];
    }
    rep(i,n){
        cout << b[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<vector<int> > Graph;
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(){
    int n,m;
    cin >> n >> m;
    vector<int>a(m);
    rep(i,m){
        cin >> a[i];
    }
    ll S = 0;
    rep(i,m){
        S+=a[i];
    }
    if(S>n)cout<<-1<<endl;
    else cout<<n-S<<endl;
    return 0;
}

Measured memory_bytes: 3668
n = int(input())
a = list(map(int, input().split()))
l = list("")
for i in range(n):
    l.append([a[i], i + 1])
l.sort()
ans = ""
for i in range(n):
    if i == n - 1:
        ans += str(l[i][1])
    else:
        ans += str(l[i][1]) + " "
print(ans)

Measured memory_bytes: 22116
import sys

N = int(input())
a = list(map(int, input().split()))
ans = 0 
count = 1
if 1 not in a :
    print(-1)
    sys.exit()

for i in range(N) :
    if a[i] == count :
        count += 1
    else :
        ans += 1
print(ans)


Measured memory_bytes: 26268
using System;
using System.Collections.Generic;
using System.Linq;
public class Simple {
    public static void Main() {
        new Simple().Solve();
    }

    void Solve(){
        List<long>[] li = new List<long>[4];
        for (int i = 0; i < 4; ++i)
            li[i] = new List<long>();
        //input
        var NW = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
        var ini= Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
        var w1 = ini[0];
        li[0].Add(ini[1]);
        for (int i = 1; i < NW[0];++i){
            var inp = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
            li[inp[0] - w1].Add(inp[1]);
        }

        //sort
        foreach (var v in li){
            v.Sort();
            v.Reverse();
        }
            
        //cal
        long ans = 0;
        for (int i = 0; i <= li[0].Count() && i * w1 <= NW[1]; ++i) {
            for (int j = 0; j <= li[1].Count(); ++j) {
                if ((i * w1 + j * (w1 + 1)) > NW[1]) break;
                for (int k = 0; k <= li[2].Count(); ++k) {
                    if ((i * w1 + j * (w1 + 1) + k * (w1 + 2)) > NW[1]) break;
                    for (int l = 0; l <= li[3].Count(); ++l) {
                        if ((i * w1 + j * (w1 + 1) + k * (w1 + 2) + l * (w1 + 3)) > NW[1]) break;
                        var sum = li[0].Take(i).Sum() + li[1].Take(j).Sum() +
                                           li[2].Take(k).Sum() + li[3].Take(l).Sum();
                        ans = Math.Max(ans, sum);
                    }
                }
            }
        }
        //res
        Console.WriteLine(ans);
    }
}

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

using namespace std;

#define NODE(x, y) ((x)*1000 + (y))
const int INF = (int)1e9;

int N;
vector<int> G[1010101];
bool used[1010101];
int dp[1010101];

// トポロジカルソートされた数列
vector<int> topo;

void dfs(int u) {
  if (used[u]) return;
  used[u] = true;
  for (auto& i : G[u]) dfs(i);
  // 帰りがけ順で追加
  topo.push_back(u);
}

void tsort() {
  for (int i = 0; i < NODE(N, N); i++)
    if (!used[i]) dfs(i);
  reverse(topo.begin(), topo.end());
}

int main() {
  cin >> N;
  int a, from, to;
  int prev;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j + 1 < N; j++) {
      cin >> a;
      a--;
      from = i, to = a;
      if (to < from) swap(from, to);
      if (j != 0) {
        G[prev].emplace_back(NODE(from, to));
      }
      prev = NODE(from, to);
    }
  }

  tsort();

  memset(used, false, sizeof(used));
  for (auto& v : topo) {
    used[v] = true;
    for (auto& nv : G[v]) {
      if (used[nv]) {
        cout << -1 << endl;
        return 0;
      }
      dp[nv] = max(dp[nv], dp[v] + 1);
    }
  }

  int ans = 0;
  for (int i = 0; i < NODE(N, N); i++) ans = max(ans, dp[i]);
  cout << ans + 1 << endl;

  return 0;
}

Measured memory_bytes: 48496
#include <map>
#include <algorithm>
#include <queue>
#include <string>
#include <iostream>
using namespace std ;

map<string,int> M ;

int move[4][2] = {1,0,-1,0,0,1,0,-1};
void get_map()
{
	string start = "01234567";
	M[start] = 0;
	queue<string> que ;
	que.push(start);
	
	while (!que.empty())
	{
		string f = que.front();
		que.pop();
		int zero = f.find_first_of('0');
		int x =zero/4;
		int y = zero%4;
		for (int i=0;i<4;i++)
		{
			int X = x+move[i][0];
			int Y = y+move[i][1];	
			if (X<0 || X>1|| Y <0|| Y>3) continue ;
			int newpos =X*4+Y;
			string item = f ;
			swap(item[zero],item[newpos]);
			if (M.find(item)!=M.end()) 
				continue ;
			else 
				{
					M[item] = M[f] + 1;
					que.push(item);
				}
		}
	}
} 

int main ()
{
	get_map();
	string s ;
	while (cin >> s)
	{
		string item;
		for (int i=0 ;i<7;i++)
		{
			cin >> item ;
			s += item;
		}
		cout <<M[s]<<endl;
	}
}


Measured memory_bytes: 5428
#include <string>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <cmath>
#include <limits>
#include <tuple>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()

int main()
{
	int N;
	cin >> N;
	vector<int> a(N);
	rep(i, N) {
		cin >> a[i];
	}
	int ans = 0;
	rep(i, N) {
		int tmp = a[i];
		while (tmp % 2 == 0) {
			ans++;
			tmp /= 2;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
if max(a)-min(a)>=2:exit(print("No"))
if len(set(a))==1:
  m=a[0]
  if m==n-1 or 2*m<=n:print("Yes")
  else:print("No")
else:
  x=a.count(min(a))
  y=n-x
  if x<max(a) and 2*(max(a)-x)<=y:print("Yes")
  else:print("No")

Measured memory_bytes: 13964
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int digit(long long x) {
    int cnt = 0;
    while (x > 0) {
        ++cnt;
        x /= 10;
    }
    return cnt;
}

int main() {
    long long N;
    cin >> N;
    
    int ans = 100000000;
    for (long long i = 1; i * i <= N; ++i) {
        long long A = i;
        long long B = N / i;
        if (A * B != N) continue;
        ans = min(ans, max(digit(A), digit(B)));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import bisect

n = int(input())
lis = list(map(int,input().split()))
lis.sort()

d = 0

for i in range(n-2):
    for j in range(i + 1, n-1):
        b = bisect.bisect_left(lis, int(lis[i] + lis[j]))
        d += max(0, b - j - 1)
print(d)


Measured memory_bytes: 45244
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;
 
int main(){
  int N,M;
  cin >> N >> M;
  vector<int> r(N,-1);

  bool flag=true;
  for(int i=0;i<M;i++){
    int s,c;
    cin >> s >> c;
    --s;
    if(r[s]!=-1 && r[s]!=c){
      flag=false;
    }
    r[s]=c;
  }

  if(flag==false){
    cout << -1 << endl;
  }else if(N==1){
    if(r[0]==-1) cout << 0 << endl;
    else cout << r[0] << endl;
  }else{
    if(r[0]==0) cout << -1 << endl;
    else{
      cout << max(1,r[0]);
      for(int i=1;i<N;i++){
	cout << max(0,r[i]);
      }
    cout << endl;
    }
  }
      
  return 0;
}


Measured memory_bytes: 256
import numpy as np
k,n = map(int,input().split())
a = np.array([int(i) for i in input().split()])
'''
隣同士の家の距離が最大のものを求めて、Kメートルから引けばよい
'''
d = np.diff(a)
d = np.append(d, k - a[-1] + a[0])
ans = k - d.max()
print(ans)

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

const static ll MOD = 998244353;

ll modcross(ll a,ll n){
    if(n == 0)return 0;
    if(n % 2 == 1)return (a+modcross(a,n-1)) % MOD;
    ll t = modcross(a,n/2) % MOD;
    return t*2 % MOD;
}

ll modpow(ll a,ll n){
    if(n == 0)return 1;
    if(n % 2 == 1)return a*modpow(a,n-1) % MOD;
    ll t = modpow(a,n/2) % MOD;
    return t*t % MOD;
}

int main(){
    ll n;cin>>n;
    vector<ll> D(n,0);
    rep(i,n)cin>>D[i];
    map<ll,ll> mp;
    rep(i,n){
        mp[D[i]]++;
    }
    if(D[0] != 0 || mp[0] != 1){
        cout<<'0'<<endl;
        return 0;
    }
    ll ans = 1;
    for(auto it = next(mp.begin(),1);it!=mp.end();it++){
        if(prev(it,1)->first + 1< it->first){
            cout<<'0'<<endl;
            return 0;
        }
        ans = modcross(ans,modpow(prev(it,1)->second,it->second));
        ans %= MOD;
    }
    cout<<ans%MOD<<endl;
    return 0;
}

Measured memory_bytes: 7296
import math

n = int(input())
x = []
y = []
for i in range(n):
  tmp = list(map(int, input().split()))
  x.append(tmp[0])
  y.append(tmp[1])

tlen = 0
for i in range(n):
  for j in range(n):
    tlen += math.sqrt((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2)

dup = 1
for i in range(n-2):
  if dup == 0:
    dup = 1
  dup *= (i+1)

tcase = 1
for i in range(n):
  tcase *= (i+1)

av = tlen / tcase * (dup * (n-1))
print(av)

Measured memory_bytes: 38384
#include <stdio.h>
#include<stdlib.h>
#define MAX 500000

int cnt=0;

void merge(int A[], int left, int mid, int right)
{
	int k, n1, n2, i, j;
	n1=mid-left;
	n2=right-mid;
	int L[n1];
	int R[n2];
	for(i=0; i<n1;i++){
		L[i]=A[left+i];
	}
	for(i=00; i<n2;i++){
		R[i]=A[mid+i];
	}
	L[n1]=1000000001;
	R[n2]=1000000001;
	i=0;
	j=0;
	for(k=left; k<right;k++){
		if(L[i]<=R[j]){
			A[k]=L[i];
			i=i+1;
			cnt++;
		}
		else{
			A[k]=R[j];
			j=j+1;
			cnt++;
		}
		
	}
}

void mergeSort(int A[], int left, int right)
{
	int mid;
	if(left+1<right){
		mid = (left+ right)/2;
		mergeSort(A, left, mid);
		mergeSort(A, mid, right);
		merge(A, left, mid, right);
	}
}

int main(void)
{
	int i, n;
	int S[MAX];
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d", &S[i]);
	}
	mergeSort(S, 0, n);
	
	for(i=0;i<n-1;i++){
		printf("%d ", S[i]);
	}
	printf("%d\n", S[n-1]);
	printf("%d\n", cnt);
	
	return 0;
}



Measured memory_bytes: 5596
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) (a).begin(), (a).end()
#define AALL(a, n) (a), ((a) + (n))
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))
#define MODNUM (INT(1e9 + 7))
#define MOD(x) ((x) % MODNUM)

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

const int INF = 2e9;
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

template <typename T>
int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T>
void chmax(T& m, T x) {
	m = max(m, x);
}

template <typename T>
void chmin(T& m, T x) {
	m = min(m, x);
}

template <typename T>
T square(T x) {
	return x * x;
}

inline int toInt(string s) {
	int v;
	istringstream sin(s);
	sin >> v;
	return v;
}

int main() {
	int n;
	scanf("%d", &n);
	VI a(n);
	REP(i, n) { scanf("%d", &a[i]); }
	sort(ALL(a));
	REP(i, n - 1) {
		if(a[i] == a[i + 1]) {
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
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; }





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<ll> a(n);
	rep(i,n) cin >> a.at(i);
	ll ans1 = 0, ans2 = 0, sum1 = 0, sum2 = 0;
	rep(i,n){
		sum1 += a.at(i);
		sum2 += a.at(i);
		if(i % 2 == 0){
			if(sum1 <= 0){
				ans1 += abs(sum1 - 1);
				sum1 = 1;
			}
			if(sum2 >= 0){
				ans2 += abs(sum2 + 1);
				sum2 = -1;
			}
		}
		else{
			if(sum2 <= 0){
				ans2 += abs(sum2 - 1);
				sum2 = 1;
			}
			if(sum1 >= 0){
				ans1 += abs(sum1 + 1);
				sum1 = -1;
			}
		}
	}
	cout << min(ans1, ans2) << endl;
}


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

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


int main(){
    string S;
    int c;
    cin >> S;
    if(S[0]=='R'&&S[1]=='R'&&S[2]=='R') c=3;
    else if(S[0]=='R'&&S[1]=='R'&&S[2]!='R' || S[0]!='R'&&S[1]=='R'&&S[2]=='R') c=2;
    else if(S[0]=='R'||S[1]=='R'||S[2]=='R') c=1;
    else c=0;
    cout << c << endl;
}

Measured memory_bytes: 3620
// 連結成分
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>

#include<queue>
#include<stack>

using namespace std;

#define MAX_N 100000

// 値の定義
const int INV = -1;

// 友達関係を保持する配列
vector<int> v_Link[MAX_N + 1];

// 連結情報を保持する配列
int ary_connection[MAX_N + 1];

void search_relation(int u_ID, int id, int user_num);

int main(void)
{
    int n, m, q, s, t;

    for(int i = 0; i < MAX_N + 1; i++)
    {
        ary_connection[i] = INV;
    }

    cin >> n >> m;

    for(int i = 0; i < m; i++)
    {
        cin >> s >> t;

        // 友達関係を双方向に設定する
        v_Link[s].push_back(t);
        v_Link[t].push_back(s);
    }

    int id = 1;

    for(int u = 0; u < n; u++)
    {
        if( ary_connection[u] == INV )
        {
            // 友達関係の検索を実施
            search_relation(u, id++, n);
        }
    }

    cin >> q;

    for(int i = 0; i < q; i++)
    {
        cin >> s >> t;

        // 質問の結果を表示する
        if( ary_connection[s] == ary_connection[t] )
        {
            // 友達関係が存在する
            printf("yes\n");
        }
        else
        {
            printf("no\n");
        }
    }

    return 0;
}

// 友達関係を検索するための関数
// u_ID : 友達関係を検索する最初のユーザーID
// id   : ary_connection[]に設定するID値
// user_num : 全ユーザー数
void search_relation(int u_ID, int id, int user_num)
{

    int user_id;

    queue<int> Q;

    // 開始点をキューにプッシュする
    Q.push(u_ID);
    // 友達関係を保存する
    ary_connection[u_ID] = id;

    while( !Q.empty() )
    {
        // キューの先頭要素を取得して, 削除する
        // ( 一人のユーザーの巡回は1回だけ )
        int u = Q.front();
        Q.pop();

        for(int v = 0; v < v_Link[u].size(); v++)
        {
            // 友達関係にあるユーザーの検索
            user_id = v_Link[u][v];

            if( ary_connection[user_id] == INV )
            {
                // ----- 繋がっている頂点が見つかった -----

                // 友達関係を保存する
                ary_connection[user_id] = id;

                // キューにプッシュして, 検索を継続する
                Q.push(user_id);
            }
        }
    }

    return;
}



Measured memory_bytes: 8992
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 998244353;//1000000007;

template<class _T> static void getval(_T& a) {
	std::cin >> a;
}
template<class _T> static void getval(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void getval(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}

static void exec();

int main()
{
	exec();
	fflush(stdout);
	return 0;
}
template <class _T> static _T tp_pow(int base, int exp)
{
	_T ans = 1;

	for (int i = 0; i < exp; i++) {
		ans *= (_T)base;
	}
	return ans;
}

static void exec()
{
	int N, P;
	getval(N, P);

	int a, odd = 0;
	for (int i = 0; i < N; i++) {
		getval(a);
		if (a % 2) odd++;
	}

	LLONG ans = 0;
	if (odd == 0 && P) {
		printf("%lld\n", ans);
		return;
	}

	if (odd) {
		ans = tp_pow<LLONG>(2, N - 1);
	}
	else {
		ans = tp_pow<LLONG>(2, N);
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 3740
def resolve():
    n = int(input())
    a = []
    b = []
    for i in range(n):
        x, y = map(int, input().split())
        a.append(x)
        b.append(y)
    a = sorted(a)
    b = sorted(b)
    if n%2 == 0:
        meda = (a[n//2-1]+a[n//2])/2
        medb = (b[n // 2 - 1] + b[n // 2]) / 2
        ans = int((medb-meda)/0.5) + 1
    else:
        meda = a[n//2]
        medb = b[n//2]
        ans = int(medb-meda+1)
    print(ans)
resolve()

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

int GCD(int x, int y)
{
	if (y > x)
	{
		swap(x, y);
	}
	while (y > 0)
	{
		int a = x % y;
		x = y;
		y = a;
	}
	return x;
}


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

	cout << GCD(x, y) << endl;

    return 0;
}

Measured memory_bytes: 3104
using System;
using static System.Console;

namespace abc170
{
    class Program
    {
        static void Main()
        {
            var n = int.Parse(ReadLine());
            var aList = ReadNumList();
            WriteLine(ND(aList));
        }
        static int ND(int[] _aList)
        {
            var aList = _aList;
            Array.Sort(aList);
            var dp = new bool[aList[aList.Length - 1] + 1];
            for (var i = 0; i < dp.Length; ++i)
            {
                dp[i] = true;
            }
            for (var i = 0; i < aList.Length; ++i)
            {
                var a = aList[i];
                if (i > 0 && a == aList[i - 1])
                {
                    dp[a] = false;
                }
                if (dp[a])
                {
                    for (var aNext = a * 2; aNext < dp.Length; aNext += a)
                    {
                        dp[aNext] = false;
                    }
                }
            }
            var count = 0;
            foreach (var a in aList)
            {
                if (dp[a])
                {
                    ++count;
                }
            }
            return count;
        }
        static int[] ReadNumList()
        {
            var line = Console.ReadLine().Split(' ');
            if (line.Length == 1 && string.IsNullOrEmpty(line[0]))
            {
                return new int[0];
            }
            var numList = new int[line.Length];
            for (var i = 0; i < line.Length; ++i)
            {
                numList[i] = int.Parse(line[i]);
            }
            return numList;
        }
    }
}


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

const int MAX = 100000;
int tab[MAX + 1];
signed main(void)
{
	int n, m, ans, maxi;
	cin >> n >> m;

	ans = maxi = 0;
	rep(i, n) tab[i] = 0;
	rep(i, m)
	{
		int l, r;
		cin >> l >> r;
		--l; --r;
		tab[l] += 1;
		tab[r + 1] += -1;
	}
	rep(i, n) tab[i + 1] += tab[i];
	rep(i, n)
	{
		if (tab[i] == m)
			ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <cmath>
#include <cstring>
#include <vector>
#include<stack>
#include<list>
#include <algorithm>
#include <unordered_map>
using namespace std;
int main()
{
	string N;
	cin>>N;
	bool flag=true;
	for(char x:N)
	{
		if(x=='7')
		{
			cout<<"Yes";
			flag=false;
			break;
		}
	}
	if(flag){
	cout<<"No";
}}


Measured memory_bytes: 3628
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define REP(i,s,n) for(int i=s; i<(n); ++i)
#define ALL(n) begin(n),end(n)
using ll = long long;
const ll INF = 1e18;
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; }

int main(){
    int A, B, C, K;
    cin >> A >> B >> C >> K;

    int ans;
    if (K <= A){
        ans = K;
    } else if (K <= A + B){
        ans = A;
    } else{
        ans = A - (K - A - B);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3624
N,K = map(int,input().split())
H = list(map(int,input().split()))
if K == 0:
  print(sum(H))
else:
  H.sort(reverse = True)
  if N>K:
    h = H[K:N]
    print(sum(h))
#    for i in range(K):
 #     del H[i]
  #  print(sum(H))
  else:
    print(0)


Measured memory_bytes: 26024
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#define lol(i,n) for(int i=0;i<n;i++)
using namespace std;
long long a[110];
int main(){
	int n;
	cin>>n;
	a[0]=2,a[1]=1;
	for(int i=2;i<=n;i++){
		a[i]=a[i-2]+a[i-1];
	}
	cout<<a[n]<<endl;
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace MyProject
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif

            var solver = new Solver();
            solver.Solve();
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class Solver
    {
        public string Calc(int X, int Y)
        {
            foreach (var tsuru in Enumerable.Range(0, X + 1))
            {
                var kame = X - tsuru;
                if (tsuru * 2 + kame * 4 == Y)
                {
                    return "Yes";
                }
            }

            return "No";
        }

        public void Solve()
        {
            var items = Console.ReadLine().Split().Select(elem => int.Parse(elem)).ToArray();
            var X = items[0];
            var Y = items[1];
            var answer = this.Calc(X, Y);
            Console.WriteLine(answer);
        }
    }
}


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

int main(){
	int k, s;
	cin >> k >> s;
	int ans=0;
	for (int i=0; i<=k; i++){
		for (int j=0; j<=k; j++){
			if (s-i-j<=k && s-i-j>=0) ans++;
		}
	}
	cout << ans << "\n";
}

Measured memory_bytes: 3556
n,k=map(int,input('').split(' '))
h=list(map(int,input('').split(' ')))

def merge_sort(arr):
    if len(arr) <= 1:
        return arr

    mid = len(arr) // 2
    # ここで分割を行う
    left = arr[:mid]
    right = arr[mid:]

    # 再帰的に分割を行う
    left = merge_sort(left)
    right = merge_sort(right)

    # returnが返ってきたら、結合を行い、結合したものを次に渡す
    return merge(left, right)


def merge(left, right):
    merged = []
    l_i, r_i = 0, 0

    # ソート済み配列をマージするため、それぞれ左から見ていくだけで良い
    while l_i < len(left) and r_i < len(right):
        # ここで=をつけることで安定性を保っている
        if left[l_i] <= right[r_i]:
            merged.append(left[l_i])
            l_i += 1
        else:
            merged.append(right[r_i])
            r_i += 1

    # 上のwhile文のどちらかがFalseになった場合終了するため、あまりをextendする
    if l_i < len(left):
        merged.extend(left[l_i:])
    if r_i < len(right):
        merged.extend(right[r_i:])
    return merged


s=0
if k>=n:
    s=0
    print(s)
else:
    c=merge_sort(h)
    c.reverse()

    s=0
    for a in range(n-k):
        s=s+c[a+k]
    
    print(s)

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

using namespace std;

int main(int argc, const char *argv[]) {
  int r, g, b;
  cin >> r >> g >> b;

  int n = b + g * 10 + r * 100;
  cout << (n % 4 == 0 ? "YES" : "NO") << '\n';
  return 0;
}

Measured memory_bytes: 3556
#define _USE_MATH_DEFINES
#include <cmath>
#include <string>
#include <vector>
#include <utility>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <numeric>
#include <array>
#include <float.h>
#include <memory>
#include <functional>
#include <iomanip>
#include <queue>
#include <random>
#include <map>
#include <set>

#pragma warning(disable:4996)

using namespace std;
using Iterator = std::string::iterator;

struct Tree {
  int value_;
  Tree* left_ = nullptr, *right = nullptr;
  Tree(int Value, Tree* l, Tree* r) {
    value_ = Value;
    left_ = l;
    right = r;
  }
};

Tree * CreateTree(Iterator& Begin, Iterator &End) {
  if (Begin == End) {
    return nullptr;
  }
  int idx = 0;
  Iterator lb = Begin + 1, le, rb, re = End - 1;
  for (; Begin != End; ++Begin) {
    if (*Begin == '(')++idx;
    else if (*Begin == ')')--idx;
    if (idx == 0) {
      le = Begin;
      string num;
      for (++++Begin; Begin != End&& *Begin != ']'; ++Begin) {
        num += *Begin;
      }
      rb = Begin + 2;
      return new Tree(stoi(num), CreateTree(lb, le), CreateTree(rb, re));
    }
  }
}

Tree* AddTree(Tree* a, Tree* b) {
  Tree* ret = new Tree(a->value_ + b->value_, nullptr, nullptr);
  if (a->left_ != nullptr&&b->left_ != nullptr) {
    ret->left_ = AddTree(a->left_, b->left_);
  }
  if (a->right != nullptr&&b->right != nullptr) {
    ret->right = AddTree(a->right, b->right);
  }
  return ret;
}

string ToString(Tree* t) {
  return "(" + (t->left_ == nullptr ? "" : ToString(t->left_)) + ")[" + to_string(t->value_) + "](" + (t->right == nullptr ? "" : ToString(t->right)) + ")";
}

int main() {
  string a, b;
  cin >> a >> b;
  auto ab = a.begin(), ae = a.end() , bb = b.begin(), be = b.end() ;
  auto *at = CreateTree(ab, ae), *bt = CreateTree(bb, be);
  auto *ans = AddTree(at, bt);
  cout << ToString(ans) << endl;
  return 0;
}

Measured memory_bytes: 3300
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>

int main()
{
	int n;
	std::cin >> n;
	std::vector<int> a;
	for (int i = 0; i < n; i++) {
		int c;
		std::cin >> c;
		a.push_back(c);
	}
	std::vector<int> b = a;
	std::sort(b.begin(), b.end(),std::greater<int>());
	int max1 = b[0];
	int max2 = b[1];

	for (auto i : a) {
		int result;
		result = (i == max1) ? max2 : max1;
		std::cout << result<<std::endl;
	}
    return 0;
}

Measured memory_bytes: 3316
/*

*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<set>
#include<queue>
#include<cmath>
#define Pair pair<int, int>
#define MP(x, y) make_pair(x, y)
#define fi first
#define se second
//#define int long long 
//#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1<<22, stdin), p1 == p2) ? EOF : *p1++)
//char buf[(1 << 22)], *p1 = buf, *p2 = buf;
using namespace std;
const int MAXN = 1e6 + 10, INF = 1e9 + 10;
const double eps = 1e-9;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int r[MAXN], l[MAXN];
char s[1001][1001];
int main() {
	int N = read(), M = read();
	for(int i = 1; i <= N; i++)
		scanf("%s", s[i] + 1);
	for(int i = 1; i <= N; i++) {
		r[i] = 1;
		for(int j = 1; j <= M; j++)
			if(s[i][j] == '#') {r[i] = 0; break;}
	}
	for(int i = 1; i <= M; i++) {
		l[i] = 1;
		for(int j = 1; j <= N; j++) {
			if(s[j][i] == '#') {l[i] = 0; break;}
		}
	}
	for(int i = 1; i <= N; i++) {
		if(r[i]) continue;
		for(int j = 1; j <= M; j++)
			if(l[j] == 0)
				putchar(s[i][j]);	
		puts("");	
	} 

    return 0;
}
/*

*/

Measured memory_bytes: 2304
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
using namespace std;

typedef int64_t ll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define vll vector<ll>
#define all(v) v.begin(), v.end()


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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define sum accumulate
#define keta fixed<<setprecision
typedef long long ll;
const int INF = 100000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 998244353LL;
int main(){
	int w,h;
	for(;;){
		std::cin >> h>>w;
		if(w==0)exit(0);
		rep(i,h){
			rep(j,w){
				if((i+j)%2==0)std::cout << "#" ;//<< std::endl;
				else std::cout << "." ;//<< std::endl;
			}
			std::cout  << std::endl;
		}
		std::cout << std::endl;
	}
}


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

int main(){
  int n; cin >> n;
  vector<int> a(n);
  for(int i=0; i<n; i++) cin >> a[i];
  auto max_itr = max_element(a.begin(),a.end());
  int max_index = distance(a.begin(), max_itr);
  int max_value = a[max_index];
  int max2_value;
  if(max_index==0) {
    max2_value = *max_element(max_itr+1, a.end());
  } else if(max_index==a.size()){
    max2_value = *max_element(a.begin(), max_itr-1);  
  } else {
    max2_value = max(*max_element(a.begin(),max_itr-1),*max_element(max_itr+1, a.end()));
  }
  for(int i=0; i<n; i++){
    cout << ( i==max_index ? max2_value : max_value ) << endl;
  }
  return 0;
}

Measured memory_bytes: 2432
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <math.h> 

using namespace std;


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

	int n, i, j, k, nn, x;
	cin >> n;

	vector<pair<int, int>> ans;

	nn = n;
	while (nn % 2 == 0) nn /= 2;
	if (nn == 1) cout << "No\n";
	else {
		// build chain of 1 to 3
		ans.push_back({ 1, 2 });
		ans.push_back({ 2, 3 });
		ans.push_back({ 3, n + 1 });
		ans.push_back({ n + 1, n + 2 });
		ans.push_back({ n + 2, n + 3 });

		for (i = 4; i < n; i += 2) {
			ans.push_back({ i, n + 1 });
			ans.push_back({ i, n + i + 1 });
			ans.push_back({ i + 1, n + 1 });
			ans.push_back({ n + i, i + 1 });
		}

		if (n % 2 == 0) {
			// find the last 1-bit of n
			x = 1;
			while (!(x & n)) x *= 2;

			ans.push_back({ x + 1, n });
			ans.push_back({ n - x, n + n });
		}

		cout << "Yes\n";
		for (auto p : ans) cout << p.first << " " << p.second << "\n";
	}



	return 0;
}



Measured memory_bytes: 4464
#include <bits/stdc++.h>
#define MAX_INT 2100000000
#define rep(i,n) for (i=1;i<=(n);++i)
using namespace std;
typedef long long int ll;
#ifdef COMPILE_IN_VCPP
#include <windows.h>
HWND GetConsoleHwnd(void)
{
#define MY_BUFSIZE 1024 // Buffer size for console window titles.
	HWND hwndFound;         // This is what is returned to the caller.
	char pszNewWindowTitle[MY_BUFSIZE]; // Contains fabricated// WindowTitle.
	char pszOldWindowTitle[MY_BUFSIZE]; // Contains original// WindowTitle.
	ULARGE_INTEGER nt;
	nt.QuadPart = GetTickCount64();
	GetConsoleTitle(pszOldWindowTitle, MY_BUFSIZE);
	wsprintf(pszNewWindowTitle, "%d%d/%d", nt.HighPart, nt.LowPart, GetCurrentProcessId());
	SetConsoleTitle(pszNewWindowTitle);
	Sleep(40);
	hwndFound = FindWindow(NULL, pszNewWindowTitle);
	SetConsoleTitle(pszOldWindowTitle);
	return(hwndFound);
}
#endif
int mod = 1e9 + 7;
int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	cout << max(0, c - a + b) << endl;
}


Measured memory_bytes: 256
#http://compro.tsutajiro.com/archive/180220_probability_dp.pdf
import sys
n = int(input())
a = list(map(int, sys.stdin.readline().split( )))
cnt =[0,0,0]
for i in range(n):
    cnt[3-a[i]] += 1
dp = [[[0 for _ in range(n+1)] for __ in range(n+1)] for ___ in range(n+1)]

dp[n][n][n] = 0
divT = [1/i for i in range(1,n+1)]

for x in range(n,cnt[1]+cnt[2]-1,-1):## -2だったのを-1に
    for y in range(x,cnt[2]-1,-1):##cnt[2]
        for z in range(y,-1,-1):
            delta = n*divT[n-z-1]#2枚以下を引くまで
            if x != n:
                dp[x][y][z] += (dp[x+1][y][z] + delta) * (n-x)
            if y != x:
                dp[x][y][z] += (dp[x][y+1][z] + delta) * (x-y)#x+1,y+1ではない
            if z != y:
                dp[x][y][z] += (dp[x][y][z+1] + delta)* (y-z)#x+1,y+1,z+1ではない
            dp[x][y][z] *=divT[n-z-1]

print(dp[cnt[1]+cnt[2]][cnt[2]][0])


Measured memory_bytes: 496648
#include<bits/stdc++.h>
using namespace std;	
#pragma GCC optimize("Ofast") 
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)	
#define fn1 for( int i =1;i<=n;	i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define endl '\n'
#define PI  3.14159265358979323846
#define MOD 1000000007
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
const int N = 2e6+5;	
const int INF = 1e18L;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
int ar[N];
int dp[N];
signed main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	IOS;
	int T=1;
	// cin >> T;
	while(T--){
		int n,d;
		cin >>n>>d;
		int ans=0;
		fn{
			int x,y;
			cin>>x>>y;
			ans+=(x*x+y*y<=d*d);
		}
		cout<<ans;
	
	
	}
	return 0;
}

Measured memory_bytes: 3648