akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
     
    #include <iostream>
    using namespace std;
     
    int main(int argc, char* argv[]){
            int N=0;
            int *A=NULL, *C=NULL;
     
            cin >> N;
     
            A = (int*)calloc(N+1, sizeof(int));
            C = (int*)calloc(N+2, sizeof(int));
            for(int i=0; i<N+1; i++){ C[i]=0; }
     
            for(int i=0; i<N; i++){
                    cin >> A[i];
                    C[A[i]]++;
            }
            long long total=0;
            for(int i=1; i<N+1; i++){
                    long long a = (long long)C[i];
                    total += a*(a-1)/2;
            }
            for(int i=0; i<N; i++){
                    long long ans = total;
                    long long v = (long long)C[A[i]];
                    if(v>1) { ans = total - (v-1);}
                    printf("%lld\n", ans);
            }
            return 0;
    }

Measured memory_bytes: 4096
#include <iostream>
#include <cstdio>
#include <cstring>
const int N=1e5+2;
int n,val[N];
bool mr[N];

inline int nxi(){
	int x=0;
	char c;
	while((c=getchar())>'9'||c<'0');
	while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
	return x;
}

int main(){
	n=nxi();
	for(int i=1;i<=n;++i) val[i]=1;
	mr[1]=1;
	for(int q=nxi();q;--q){
		const int x=nxi(),y=nxi();
		mr[y]|=mr[x];
		if(!--val[x]) mr[x]=0;
		++val[y];
	}
	int ans=0;
	for(int i=1;i<=n;++i){
		ans+=mr[i];
	}
	printf("%d\n",ans);
	return 0;
}

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

template <class T> void chmin(T &x, T y)
{
    if(x>y) x=y;
}

main()
{
    int h,w; cin>>h>>w;
    vector<string> s(h);
    for(int i=0; i<h; ++i)
    {
        cin>>s[i];
    }
  
    int dist[404][404];
    for(int i=0; i<400; ++i)
    {
        for(int j=0; j<400; ++j)
        {
            dist[i][j]=1e7;
            if(i==j) dist[i][j]=0;
        }
    }
    
    int dx[]={1,0,-1,0};
    int dy[]={0,1,0,-1};
    for(int i=0; i<h; ++i)
    {
        for(int j=0; j<w; ++j)
        {
            int now=i*w+j,to;
            if(s[i][j]=='#') continue;
            for(int k=0; k<4; ++k)
            {
                int ii=dx[k]+i;
                int jj=dy[k]+j;
                to=ii*w+jj;
                if(min(ii,jj)>=0 and ii<h and jj<w and s[ii][jj]=='.')
                {
                    dist[now][to]=1;
                }
            }
        }
    }
  
    for(int i=0; i<h*w; ++i)
    {
        for(int j=0; j<h*w; ++j)
        {
            for(int k=0; k<h*w; ++k)
            {
                chmin(dist[j][k],dist[j][i]+dist[i][k]);
            }
        }
    }

    int ans=0;
    for(int i=0; i<h*w; ++i)
    {
        for(int j=0; j<h*w; ++j)
        {
            if(i!=j and dist[i][j]!=1e7)
            {
                ans=max(ans,dist[i][j]);
            }
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 896
import heapq

n, m = map(int, (input().split()))
A = list(map(int, input().split()))
for i in range(n):
    A[i] = A[i]*(-1)

heapq.heapify(A)

for i in range(m):
    value = heapq.heappop(A)
    value /= 2
    heapq.heappush(A, value)

ans = 0
for a in A:
    ans += int(-a)
print(ans)



Measured memory_bytes: 14180
import java.io.*;

/**
 * Copyright © 2018 Chris. All rights reserved.
 *
 * @author Chris
 * 2018/6/23 11:55
 * @see meituan.n2018.Bturn
 */
public class Main {


    private static BufferedReader br;
    private static StreamTokenizer st;
    private static PrintWriter pw;

    private static void solve() throws IOException {
        int R = nextInt();
        if (R < 1200) {
            pw.print("ABC");
        } else if (R < 2800) {
            pw.print("ARC");
        } else {
            pw.print("AGC");
        }
    }

    public static void main(String args[]) throws IOException {
//        boolean oj = System.getProperty("ONLINE_JUDGE") != null;
//        if (!oj) {
//            System.setIn(new FileInputStream("src/in.txt"));
//        }
        br = new BufferedReader(new InputStreamReader(System.in));
        st = new StreamTokenizer(br);
        pw = new PrintWriter(new OutputStreamWriter(System.out));
        st.ordinaryChar('\''); //指定单引号、双引号和注释符号是普通字符
        st.ordinaryChar('\"');
        st.ordinaryChar('/');

        long t = System.currentTimeMillis();
        solve();
//        if (!oj) {
//            pw.println("[" + (System.currentTimeMillis() - t) + "ms]");
//        }
        pw.flush();
    }


    private static int nextInt() throws IOException {
        st.nextToken();
        return (int) st.nval;
    }

    private static long nextLong() throws IOException {
        st.nextToken();
        return (long) st.nval;
    }

    private static double nextDouble() throws IOException {
        st.nextToken();
        return st.nval;
    }

    private static String[] nextSS(String reg) throws IOException {
        return br.readLine().split(reg);
    }

    private static String nextLine() throws IOException {
        return br.readLine();
    }
}

Measured memory_bytes: 21076
#include <bits/stdc++.h>
using namespace std;
//define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
// 許容する誤差ε
#define EPS (1e-10)
// 2つのスカラーが等しいかどうか
#define EQ(a,b) (abs((a)-(b)) < EPS)
// 2つのベクトルが等しいかどうか
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
//template
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << p.first << " " << p.second;return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if (it != v.begin())os << " ";os << *it;
  }return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void print(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void print(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
//typedef
typedef complex<double> Point;
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;

const int MAX = 10000000;
bool prime[MAX+1], ans[MAX+1];
void init(){
  fill(prime, prime+(MAX+1), true);
  prime[0] = prime[1] = false;
  for(int i = 2;i*i <= MAX;i++){
    if(prime[i])for(int j = 2;i*j <= MAX;j++){
      prime[i*j] = false;
    }
  }
  repi(i,13,MAX+1){
    if(prime[i] and prime[i-2] and prime[i-6] and prime[i-8]){
      ans[i] = true;
    }
  }
}

signed main(){
  init();
  while(1){
    int n;cin >> n;
    if(n == 0)break;
    drep(i,n,13){
      if(ans[i]){cout << i << endl;break;}
    }
  }
	return 0;
}







Measured memory_bytes: 15712
n = int(input())
arr = list(map(int,input().split()))
add = sum(arr)
if add>0:
	x = int(add/n + 0.5)
else:
	x = int(add/n - 0.5)

ans = 0
for i in range(len(arr)):
	ans += ((x-arr[i])*(x-arr[i]))
print(ans)

Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using edge = pll; //first: to, second: cost;
const int max_v = 110;
using pp = pair<ll, pll>;

int V;
vector<edge> G[max_v];
ll d[max_v];
map<pll, bool> passed; //辺{a, b}が通過済みかどうか

void dijkstra(int s){ 
    priority_queue<pp, vector<pp>, greater<pp>> que;
    fill(d, d+V, INF); 
    d[s] = 0; 
    que.push(pp(0, {-1, s}));

    while(!que.empty()){
        pp p = que.top(); que.pop();
        int f = p.second.first, t = p.second.second;
        int v = t;
        if(d[v] < p.first) continue; 
        //ここで通過チェック
        if(f != -1){
            pll p1{f, t}, p2{t, f};
            passed[p1] = true; passed[p2] = true;
        }

        for(edge e: G[v]){
            int to = e.first; ll cost = e.second;
            if(d[to] > d[v] + cost){
                d[to] = d[v] + cost;
                que.push(pp(d[to], {v,to}));
            }
        }
    }
}

int main(){
    int m; cin >> V >> m;
    rep(i, m){
        int a, b, c; cin >> a >> b >> c; a--; b--;
        G[a].emplace_back(b, c);
        G[b].emplace_back(a, c);
    }
    rep(i, V) dijkstra(i);

    ll res = (m*2 - passed.size()) / 2;
    cout << res << ln;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define int long long
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const array<pair<int,int>,4> fd{make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

signed main(){
  int n;cin>>n;int p[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997};
  int a[1001];rep(i,1001)a[i] = 0;
  repd(i,2,n+1){
    int n = i;
    rep(j,168){
      while(!(n%p[j])){
        n /= p[j];
        a[p[j]]++;
      }
    }
  }
  int ans = 1;
  rep(i,1001){
    ans *= (a[i] + 1)%MOD;
    ans %= MOD;
  }
  cout << ans << endl;
}


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

#define ll long long
#define INF 1<<31-1
#define LNF 9223372036854775807
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
//#define MOD 998244353
#define NUM 200010
 
void swap(int* a,int* b){int tmp=*a;*a=*b;*b=tmp;}
int abs(int a){if(a<0)return -a;return a;}
int dup(int a,int d){if(a%d==0)return a/d;else return a/d+1;}
int mod(int a,int m){if(a<0)return a%m+m;else return a%m;}

void swapl(ll* a,ll* b){ll tmp=*a;*a=*b;*b=tmp;}
ll absl(ll a){if(a<0)return -a;return a;}
ll dupl(ll a,ll d){if(a%d==0)return a/d;else return a/d+1;}
ll modl(ll a,ll m){if(a<0)return a%m+m;else return a%m;}

ll GCD(ll a,ll b){ll c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
ll LCM(ll a,ll b){return a*b/GCD(a,b);}

ll factorial(ll n, ll m) {return n < m ? 1 : n*factorial(n-1, m);}

int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

// typedef struct 
// {
//     ll h;
//     ll v;
// } box;


// int cmp_qwe(const void*a, const void*b){return ((box*)b)->a - ((box*)a)->a;}
int int_sort( const void * a , const void * b ) {
  return strcmp(( char * )a , ( char * )b );
}

// ll dp[3000][3000];
// box u[2000];


int main(){
  ll n, a, sum=0;
  
  char s[200000][12];

  scanf("%lld", &n);

  for (int i = 0; i < n; i++)
  {
      scanf("%s", &s[i][0]);
  }
  qsort(s, n, sizeof(s[0]), int_sort);

  sum++;
  a=0;
  for (int i = 0; i < n; i++)
  {
      if(strcmp(s[a], s[i]) != 0) {
          sum++;
          a = i;
      }
  }

  printf("%lld", sum);

  return 0;
}

Measured memory_bytes: 6204
s=str(input())
cnt=0
for i in range(len(s)):
    if i%2==0:
        if s[i]=="0":
            cnt+=1
        else:
            continue
    if i%2!=0:
        if s[i]=="1":
            cnt+=1
        else:
            continue
print(min(cnt,len(s)-cnt))

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

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

#define ll      long long
#define Fi      first
#define Se      second
#define Pb      push_back
#define vi      vector<int>
#define vs      vector<string>
#define vp      vector<pair<int,int>>
#define vvi     vector<vector<int>>
#define vvp     vector<vector<pair<int,int>>>
using Graph  =  vector<vector<int>>; //Caution!! Segmentation Fault!! Don't forget to add +1!

#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define output_s(s) printf("%s\n",(s).c_str())

#define rep(i,n)        for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m)      for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m)     for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m)    for(int i=(int)(n);i>=(int)(m);i--)
#define SRepS(i,n,m)     for(int i=(int)(n);i*i<=(int)(m);i++)
#define RepA(x)         for(auto &item:(x))

void CINT(){} //@shibh308's template
template<class Head,class... Tail> void CINT(Head&& head,Tail&&... tail){cin>>head; CINT(move(tail)...);}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
#define VCIN(x) for(auto &item:x) cin>>item

void OUT(){}
template<class Head,class...Tail> void OUT(Head&& head,Tail&&...tail){cout<<head<<(sizeof...(tail)?" ":"\n"); OUT(move(tail)...);}
#define COUT(...) OUT(__VA_ARGS__)

template<typename TypeInt>TypeInt GCD(TypeInt a,TypeInt b){return a%b==0?b:GCD(b,a%b);} //最大公約数
template<typename TypeInt>TypeInt LCM(TypeInt a,TypeInt b){return a*b/GCD(a,b);} //最小公倍数
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
template<class T>bool comp(T a,T b){return abs(a)<abs(b);} //比較関数

void YES(bool f){printf(f?"YES\n":"NO\n");}
void Yes(bool f){printf(f?"Yes\n":"No\n");}
void Possible(bool f){printf(f?"Possible\n":"Impossible\n");}
void POSSIBLE(bool f){printf(f?"POSSIBLE\n":"IMPOSSIBLE\n");}

//----------------------library------------------------//

//const int dx[4]={1,0,-1,0};
//const int dy[4]={0,1,0,-1};
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int NMAX = 200;
const int INF = 1e9;
const int MOD = 1e9+7;
bool flag;

//----------------------Global-------------------------//

signed main(){
    CIN(N);
    vi A(N+1);VCIN(A);
    int B;
    ll ans=0;
    rep(i,N){
        cin>>B;
        ll cur=min(A[i]+A[i+1],B);
        ans+=cur;
        A[i+1]-=cur-min(B,A[i]);   
    }
    printf("%lld\n",ans);

    return 0;
}


Measured memory_bytes: 640
// ワーシャルフロイド法自作ライブラリ
/* option1 経路復元 start,endを指定することで、任意の二点間の最短距離の経路を表示*/
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define dump1d_arr(array) REP(i,array.size()) cerr << #array << "[" << (i) << "] ==> " << (array[i]) << endl;
#define dump2d_arr(array) REP(i,array.size()) REP(j,array[i].size()) cerr << #array << "[" << (i) << "]" << "[" << (j) << "] ==> " << (array[i][j]) << endl;
#define dump(x)  cerr << #x << " => " << (x) << endl;
#define loINF 2147483647
//#define TRACE_ROUTE
using namespace std;

typedef vector<long> VI;
typedef vector<VI> VVI;
vector<vector<long>> dist;
#ifdef TRACE_ROUTE
	vector<vector<long>> nex;
#endif

short Warshall_Floyd(long V){
	// 頂点は 0 ~ V 
	REP(i,V+1) dist[i][i] = 0;	//初期化
	FOR(i,1,V+1){
		FOR(j,1,V+1){
			FOR(k,1,V+1){
				if (dist[j][i] == 2147483647 || dist[i][k] == 2147483647) continue;
				if (dist[j][k] > dist[j][i] + dist[i][k]){
					dist[j][k] = dist[j][i] + dist[i][k];
					#ifdef TRACE_ROUTE
						nex[j][k] = nex[j][i];
					#endif
				}
				#ifdef TRACE_ROUTE
				else {
					if (j != i && dist[j][k] == dist[j][i] + dist[i][k])
						nex[j][k] = min({nex[j][i],nex[j][k]});
				}
				#endif
				if (dist[j][j] < 0) return (-1);
			}
		}
	}

	//dump2d_arr(dist);
	return 0;
}

int main(void){
	long V,E;	//頂点数,辺数
	cin >> V >> E;

	dist = VVI (V+1,VI(V+1,loINF));


	#ifdef TRACE_ROUTE
		nex = vector<vector<long>>(V+1,vector<long>(V+1,0));
		REP(i,V+1) REP(j,V+1) nex[i][j] = j;
	#endif

	REP(i,E){
		long v1,v2,dis;
		cin >> v1 >> v2 >> dis;
		dist[v1][v2] = dis;
		dist[v2][v1] = dis;
	}
	VVI e = dist;
	//dump2d_arr(e);

	long retval = Warshall_Floyd(V); // 頂点数に気をつける。

	long cnt = 0;

	FOR(i,1,V+1){
		FOR(j,1,V+1){
			if (e[i][j] != loINF && e[i][j] > dist[i][j]) cnt++;
		}
	}
	cout << cnt/2 << endl;

}



// 経路復元用
#ifdef TRACE_ROUTE
string trace_route(long start ,long goal){
	string route("");
	long current;
	for(current = start;current!=goal;current = nex[current][goal])
		route += (to_string(current) + "-");
	route += to_string(goal);
	return route;
}
#endif

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <unordered_map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define INF 1000000000000000000
#define MOD 1000000007
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

int main() {
	int n;
	cin >> n;
	vector <int> A(n);
	for (int i = 0; i < n; i++) {
		cin >> A[i];
	}
	int ans = MOD;
	for (int val = -100; val <= 100; val++) {
		int cur = 0;
		for (int i = 0; i < n; i++) {
			cur += (A[i] - val) * (A[i] - val);
		}
		ans = min(ans, cur);
	}
	cout << ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int x;

bool is_prime(int n) {
  for(int i=2; i * i <= n; i++) {
    if(n % i == 0) return false;
  }
  return n != 1;
}

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

  cin >> x;

  while(x <= 1000000) {
    if(is_prime(x)) break;
    x++;
  }

  cout << x << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define inf  1000000000
#define mod  1e9+1
#pragma GCC optimization ("O3")
using namespace std;
const long long int N = 6999999;
#define all(x) begin(x),end(x)
int main()
{
 
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  long long int p,h,cd = 1e9+1,acd = 1e9+1;
  cin >> p >> h;
  vector <long long int> m(h),md(h);
  for (int i = 0; i < h; ++i)
  {
    cin >> m[i];
  }
  cd = min(m[h-1]-m[0],cd);
  for (int i = 1; i < h; ++i)
  {
    cd = min(p-m[i]+m[i-1],cd);
  }
  for (int i = 1; i < h ; ++i)
  {
    if(i == h-1)
    {
      acd = min(p-(p-m[i]),acd);
      continue;
    }
    acd = min(p-(m[i+1]-m[i]),acd);
  }
  cout << min(cd,acd);
  return 0;
} 


Measured memory_bytes: 3328
#include <stdio.h>
#include <stdlib.h>

int gcd(int a, int b)
{
    int r = 0;
    while(r = a % b){
        a = b;
        b = r;
    }
    return b;
}


int main(void)
{
    int i, n;
    scanf("%d", &n);
    int a[n], gL[n], gR[n], gM[n];
    
    for ( i = 0; i < n; i++)
        scanf("%d", &a[i]);

    gL[0] = a[0];
    for ( i = 0; i < n - 1; i++)
        gL[i + 1] = gcd(gL[i], a[i + 1]);
    

    gR[n - 1] = a[n - 1];
    for (i = n - 1; i > 0; i--)
        gR[i - 1] = gcd(a[i - 1], gR[i]);

    gM[0] = gR[1];
    gM[n - 1] = gL[n - 2];

    for (i = 0; i < n - 2; i++)
        gM[i + 1] = gcd(gL[i], gR[i + 2]);

    int max = 0;
    for (i = 0; i < n; i++){
        if(max < gM[i]){
            max = gM[i];
        }
    }
    printf("%d\n", max);
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repin(a, n)  \
    vector<ll> a(n); \
    rep(i, n) { cin >> a[i]; }
#define repins(a, n)     \
    vector<string> a(n); \
    rep(i, n) { cin >> a[i]; }
#define repind(a, n)     \
    vector<double> a(n); \
    rep(i, n) { cin >> a[i]; }
#define in(a) \
    ll a;     \
    cin >> a;
#define ins(a) \
    string a;  \
    cin >> a;
#define ind(a) \
    double a;  \
    cin >> a;
template <class T>
inline void out(T a) {
    cout << a << endl;
}
inline void out(double a) { printf("%.10f\n", a); }
#define all(x)        (x).begin(), (x).end()
#define rep2(i, a, b) for (ll i = (a); i < (b); ++i)
#define yes           out("Yes");
#define no            out("No");

int main() {
    in(N);
    ll a, ans;

    rep2(i, 1, N + 1) {
        a = sqrt(i);
        ans = 0;
        rep2(x, 1, a) {
            rep2(y, x, a) {
                rep2(z, y, a) {
                    if (x * x + y * y + z * z + x * y + y * z + z * x == i) {
                        if (x != y && y != z && z != x) {
                            ans += 6;
                        } else if (x == y && y == z && z == x) {
                            ans++;
                        } else {
                            ans += 3;
                        }
                    }
                }
            }
        }
        out(ans);
    }
}

Measured memory_bytes: 3560
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char a[10010];
	char b[10010];
	scanf("%s",&a);
	int t=0;
	for(int i=0;i<strlen(a);i++)
	{
		if(a[i]=='B')
		t--;
		else
		{
			b[t]=a[i];
			t++;
		}
		if(t<0)
		t=0;
	}
	b[t]='\0';
	printf("%s",b);
	return 0;
}

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

int main(){
  int n,k,i,j,l,wa=0,kei,cost;
  cin>>n>>k;
  int a[n],b[n];
  for(i=0;i<n;i++){
    cin>>a[i];
    wa+=a[i];
  }
  for(i=wa;i>=2;i--){
    if(wa%i==0){
      kei=0;
      cost=0;
      for(j=0;j<n;j++){
        b[j]=a[j]%i;
        kei+=b[j];
      }
      sort(b,b+n);
      for(l=1;l<=kei/i;l++){
        cost+=i-b[n-l];
      }
    }
    if(cost<=k){
      break;
    }
  }
  cout<<i;
}
  

Measured memory_bytes: 384
import sys
 
def kensho(x,tlist):
    for lis in tlist:
        if((x>>(lis[1]-1)) & 1 == lis[2]):
            pass
        else:
            return -1
 
    return bin(x).count('1')
 
 
def main():
    N = int(input())
    xy=[]
    ans=0
 
    for i in range(1,N+1):
        An= int(input())
        for j in range(0,An):
            x, y = map(int, input().split())
            xy.append([i,x,y])
 
    cnt = N
 
    tlist=[]
    for x in range (2 ** cnt):
        for y in range(cnt):
            if((x>>y) & 1):
                for z in xy:
                    if(z[0]==y+1):
                        tlist.append(z)
 
        anstack = kensho(x,tlist)
        if(ans<anstack):
            ans=anstack
 
        del tlist[:]
 
    print(ans)
 
main()

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

using namespace std;
using ll = long long;
using P = pair<int, int>;
#define all(c) (c).begin(), (c).end()
const int INF = 1e9 + 1;
const ll LINF = 1e18 + 1;
const ll MOD = 1e9 + 7;

bool check(vector<int> a, int idx, int n, int m, int v, int p) {
  ll rest = (ll)m * (v - 1);
  int base = a[idx] + m;
  a.erase(a.begin() + idx);
  for (int i = 0; i < p - 1; ++i) {
    a[i] += m;
    rest -= m;
  }
  int i = p - 1;
  while (i < a.size() && rest > 0) {
    ll t = min(m, max(0, base - a[i]));
    if (t > rest) t = rest;
    rest -= t;
    a[i] += t;
    ++i;
  }
  // cout << a << " " << idx << " " << base << " " << rest << endl;
  return a[p - 1] <= base && rest <= 0;
}

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

  int n, m, v, p;
  cin >> n >> m >> v >> p;

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

  sort(all(a));
  reverse(all(a));
  int ok = -1, ng = n;

  while (abs(ok - ng) > 1) {
    int mid = (ok + ng) / 2;
    if (check(a, mid, n, m, v, p)) {
      ok = mid;
    } else {
      ng = mid;
    }
  }

  cout << ok + 1 << endl;
  return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        while (true){
            int H = sc.nextInt();
            int W = sc.nextInt();
            if (H == 0 || W == 0){
                break;
            }
            for (int i = 0; i < H; i++){
                for (int j = 0; j < W; j++){
                    if (i == 0 || i == (H - 1)){
                        System.out.print("#");
                    } else if (j == 0 || j == (W - 1)){
                        System.out.print("#");
                    } else {
                        System.out.print(".");
                    }
                }
                System.out.println();
            }
            System.out.println();
        }
    }
}



Measured memory_bytes: 34992
n,x = map(int,input().split())
y = list(map(int,input().split()))
a = [abs(x-y[i]) for i in range(n)]
def gcd(a,b):
    return gcd(b,a%b) if b else abs(a)
ans = a[0]
for i in range(1,n):
    ans = gcd(ans,a[i])
print(ans)

Measured memory_bytes: 14228
def resolve():
    N = int(input())
    W = [input() for _ in range(N)]
    if len(set(W)) != N:
        print("No")
        return
    l = W[0][0]
    for w in W:
        if w[0] != l:
            print("No")
            return
        l = w[-1]
    print("Yes")

resolve()

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

int main() {
    int N,K;
    cin >> N >> K;
    
    int l = 0;
    int x;
    
    for (int i; i<N; i++){
        cin >> x;
        if ((x-0)<(K-x)) l+=x-0;
        else l+=K-x;
    }
    
    cout << l*2 << endl;
}


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

int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  
  if(A*B>C*D){
    cout << A*B << endl;
  }
  else if(A*B<C*D){
    cout << C*D << endl;
  }
  else{
    cout << A*B << endl;
  }
}


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

int main(){
  int H,W;
  cin >> H >> W;
  vector<string> S(H);
  for(int i = 0; i < H; i++){
    cin >> S[i];
  }
  int row[H][W];
  int column[H][W];
  for(int i  = 0; i < H; i++){
    int cnt = 0;
    int j;
    for(j = 0; j < W; j++){
      if(S[i][j] == '.') cnt++;
      else{
	row[i][j] = 0;
	for(int k = j - cnt; k < j; k++){
	  row[i][k] = cnt;
	}
	cnt = 0;
      }
    }
    if(cnt){
      for(int k = j - cnt; k < j; k++){
	row[i][k] = cnt;
      }
    }
  }

  for(int i = 0; i < W; i++){
    int cnt = 0;
    int j;
    for(j = 0; j < H; j++){
      if(S[j][i] == '.') cnt++;
      else{
	column[j][i] = 0;
	for(int k = j - cnt; k < j; k++){
	  column[k][i] = cnt;
	}
	cnt = 0;
      }
    }
    if(cnt){
      for(int k = j - cnt; k < j; k++){
	column[k][i] = cnt;
      }
    }
  }

  int ans[H][W];

  int max_ans = 0;
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      int tmp = row[i][j] + column[i][j] - 1;
      max_ans = max(max_ans, tmp);
    }
  }

  cout << max_ans << endl;
  
}


Measured memory_bytes: 35584
N = int(input())
A = []
B = []
for i in range(N):
  Anew, Bnew = map(int,input().split())
  A.append(Anew)
  B.append(Bnew)
A.sort()
B.sort()
if N % 2 == 0:
  min = (A[N//2-1] + A[N//2]) / 2
  max = (B[N//2-1] + B[N//2]) / 2
  print(int((max-min)*2+1))
else:
  min = (A[(N-1)//2])
  max = (B[(N-1)//2])
  print(max-min+1)

Measured memory_bytes: 25552
def getlist():
	return list(map(int, input().split()))

n = int(input())
p = getlist()

ans = 0
for i in range(n - 2):
	if p[i] < p[i + 1] and p[i + 1] < p[i + 2]:
		ans += 1
	elif p[i] > p[i + 1] and p[i + 1] > p[i + 2]:
		ans += 1
	else:
		pass

print(ans)

Measured memory_bytes: 38256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        an: [i32; n]
    }
    println!("{}", solve(n, an));
}

fn solve(_n: usize, an: Vec<i32>) -> i32 {
    let mut an = an;
    let mut min_hp = *an.iter().min().unwrap();
    loop {
        an = an.into_iter().filter(|&x| x % min_hp != 0).map(|x| x % min_hp).collect();
        an.push(min_hp);
        if an.iter().count() == 1 {
            break;
        }
        match an.iter().min() {
            Some(&x) => min_hp = x,
            None => break,
        }
    }
    min_hp
}


Measured memory_bytes: 6396
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template<u32 M = 1000000007>
struct modint{
    u32 val;
    modint(): val(0){}
    template<typename T>
    modint(T t){t %= (T)M; if(t < 0) t += (T)M; val = t;}

    modint pow(ll k) const {
        modint res(1), x(val);
        while(k){
            if(k&1) res *= x;
            x *= x;
            k >>= 1;
        }
        return res;
    }
    template<typename T>
    modint& operator=(T t){t %= (T)M; if(t < 0) t += (T)M; val = t; return *this;}
    modint inv() const {return pow(M-2);}
    modint& operator+=(modint a){val += a.val; if(val >= M) val -= M; return *this;}
    modint& operator-=(modint a){if(val < a.val) val += M-a.val; else val -= a.val; return *this;}
    modint& operator*=(modint a){val = (u64)val*a.val%M; return *this;}
    modint& operator/=(modint a){return (*this) *= a.inv();}
    modint operator+(modint a) const {return modint(val) +=a;}
    modint operator-(modint a) const {return modint(val) -=a;}
    modint operator*(modint a) const {return modint(val) *=a;}
    modint operator/(modint a) const {return modint(val) /=a;}
    modint operator-(){return modint(M-val);}
    bool operator==(const modint a) const {return val == a.val;}
    bool operator!=(const modint a) const {return val != a.val;}
    bool operator<(const modint a) const {return val < a.val;}
};
using mint = modint<MOD>;

int main() {
    int n;
    cin >> n;
    vector<mint> v(n);
    for (auto &&i : v) scanf("%d", &i.val);
    mint a = accumulate(v.begin(),v.end(), mint(0));
    a *= a;
    for (int i = 0; i < n; ++i) {
        a -= v[i]*v[i];
    }
    a *= 500000004;
    cout << a.val << "\n";
    return 0;
}

Measured memory_bytes: 4040
#include <bits/stdc++.h>
using namespace std;
//define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// 許容する誤差ε
#define EPS (1e-10)
// 2つのスカラーが等しいかどうか
#define EQ(a,b) (abs((a)-(b)) < EPS)
// 2つのベクトルが等しいかどうか
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
//template
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
      }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
//typedef
typedef complex<double> Point;
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;



double dot(Point a, Point b) {
  return (a.real() * b.real() + a.imag() * b.imag());
}
double cross(Point a, Point b) {
  return (a.real() * b.imag() - a.imag() * b.real());
}

vector<Point> vec(3);
Point p;
bool solve(int f){
  bool ans = true;
  rep(i,3){
    Point v = vec[(i+1)%3]-vec[i];
    if(f and cross(v, p-vec[i]) < 0)ans = false;
    if(!f and cross(v, p-vec[i]) > 0)ans = false;
  }
  return ans;
}
signed main(){
  double X[3], Y[3], Xp, Yp;
  while(cin>>X[0]>>Y[0]>>X[1]>>Y[1]>>X[2]>>Y[2]>>Xp>>Yp){
    rep(i,3)vec[i] = Point(X[i], Y[i]);
    p = Point(Xp, Yp);
    if(solve(0) or solve(1))printf("YES\n");
    else printf("NO\n");
  }
	return 0;
}











Measured memory_bytes: 3228
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
    int h, w; cin >> h >> w;
    auto g = make_v(h+1, w+1, '0');
    FOR(i, 1, h+1)FOR(j, 1, w+1) cin >> g[i][j];

    auto lx = make_v(2, h+1, w+2, 0), ly = make_v(2, h+2, w+1, 0);
    FOR(i, 1, h+1) lx[1][i][w+1] = w+1; 
    FOR(i, 1, w+1) ly[1][h+1][i] = h+1;

    FOR(i, 1, h+1)FOR(j, 1, w+1){
        if(g[i][j] == '#'){
            lx[0][i][j] = j;
            ly[0][i][j] = i;
        } else {
            lx[0][i][j] = lx[0][i][j-1]; 
            ly[0][i][j] = ly[0][i-1][j];
        }
    }

    for(int i=h; i>=1; i--)for(int j=w; j>=1; j--){
        if(g[i][j] == '#'){
            lx[1][i][j] = j;
            ly[1][i][j] = i;
        } else {
            lx[1][i][j] = lx[1][i][j+1];
            ly[1][i][j] = ly[1][i+1][j];
        }
    }

    int ans = 0;
    FOR(i, 1, h+1)FOR(j, 1, w+1){
        if(g[i][j] == '#') continue;
        int x = (j - lx[0][i][j]) + (lx[1][i][j] - j) - 1;
        int y = (i - ly[0][i][j]) + (ly[1][i][j] - i) - 1;

        ans = max(ans, x + y - 1);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 82816
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
	int P, Q, R;
	cin >> P >> Q >> R;
	if (P < Q) {
		if (Q < R) cout << P + Q;
		else cout << P + R;
	}
	else {
		if (P < R) cout << P + Q;
		else cout << Q + R;
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//vacation
struct activity{
    int A,B,C;
};
int solve(vector<activity> ar, int n){
    int dp[n+1][3];
    dp[1][0] = ar[1].A;
    dp[1][1] = ar[1].B;
    dp[1][2] = ar[1].C;
    for(int i=2;i<=n;i++){
        dp[i][0] = ar[i].A + max(dp[i-1][1], dp[i-1][2]);
        dp[i][1] = ar[i].B + max(dp[i-1][0], dp[i-1][2]);
        dp[i][2] = ar[i].C + max(dp[i-1][1], dp[i-1][0]);
    }
    return max(dp[n][0], max(dp[n][1], dp[n][2]));
}
int main() {
	int n;
	cin>>n;
	vector<activity> ar(n+1);
	for(int i=1;i<=n;i++){
	    cin>>ar[i].A;
	    cin>>ar[i].B;
	    cin>>ar[i].C;
	}
	cout<<solve(ar, n);
	
	return 0;
}


Measured memory_bytes: 6688
N,X=map(int,input().split())
A=list(map(int,input().split()))
D=0
cnt=1
if sum(A)<= X:
  print(N+1)
  exit()
else:
  for i in range(X+1):
    D+=A[i]
    if D <= X:
      cnt+=1
    else:
      print(cnt)
      exit()

Measured memory_bytes: 3060
n = int(input())

nums = []
maxN = 0
secondN = 0

for i in range(n):
    num = int(input())
    nums.append(num)
    if maxN < num:
        secondN = maxN
        maxN = num
    elif secondN < num:
        secondN = num

for i in range(n):
    if nums[i] != maxN:
        print(maxN)
    else:
        if secondN == maxN:
            print(maxN)
        else:
            print(secondN)

Measured memory_bytes: 12532
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

int main(){
  int n;
  cin >> n;
  int sum = 0, a[n];
  REP(i, n){
    cin >> a[i];
    sum += a[i];
  }

  int p = sum / n, q = p + 1;
  int s1 = 0, s2 = 0;

  REP(i, n){
    s1 += (p - a[i]) * (p - a[i]);
    s2 += (q - a[i]) * (q - a[i]);
  }

  int ans = min(s1, s2);

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
    int x,y,z;
    cin>>x>>y>>z;
    x-=z*2;
    int ans=0;
    for(int i=1 ; i<=INT_FAST32_MAX ; i++)
    {
        if(i*y+(i-1)*z>x)
        {
            ans=i;
            break;
        }
    }
    ans--;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3604
///
// File:  d.cpp
// Author: ymiyamoto
//
// Created on Wed Nov 22 00:06:50 2017
//

#include <array>
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

static array<array<uint32_t, 10>, 10> dists;

int32_t main()
{
  uint32_t H, W;
  cin >> H >> W;

  for (uint32_t i = 0; i <= 9; i++) {
    for (uint32_t j = 0; j <= 9; j++) {
      cin >> dists[i][j];
    }
  }

  for (uint32_t k = 0; k <= 9; k++) {
    for (uint32_t i = 0; i <= 9; i++) {
      for (uint32_t j = 0; j <= 9; j++) {
        dists[i][j] = min(dists[i][j], dists[i][k] + dists[k][j]);
      }
    }
  }

  uint64_t count = 0;
  for (uint32_t i = 0; i < H; i++) {
    for (uint32_t j = 0; j < W; j++) {
      int32_t val;
      cin >> val;
      if (val >= 0) {
        count += dists[val][1];
      }
    }
  }
  cout << count << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
const int N=100005;
using namespace std;
int a,b,k;
int main(){
	cin>>k>>a>>b;
	for(int i=a;i<=b;i++)
	    if(i%k==0) {cout<<"OK";return 0;}
	cout<<"NG";
    return 0;
}

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


int find(int x)
{
    while (p[x] != x) {
        p[x] = p[p[x]];
        x = p[x];
    }
    return x;
}

void merge(int x, int y)
{
    int a = find(x);
    int b = find(y);
    if (a == b) return;
    if (sz[a] < sz[b]) {
        p[a] = b;
        sz[b] += sz[a];
    } else {
        p[b] = a;
        sz[a] += sz[b];
    }
}

int main()
{
    int n, m;
    cin >> n >> m;
    rep(i, n) {
        p[i] = i;
        sz[i] = 1;
    }
    rep(i, m) {
        int x, y;
        cin >> x >> y;
        merge(x-1, y-1);
    }
    int ans = 0;
    vector<int> counter(n);
    rep(i, n) counter[find(p[i])]++;
    rep(i, n) ans = max(counter[i], ans);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5588
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var l1 = ReadIntArray();
        var hp = l1[0];
        var sp_types = l1[1]; 
        var sp_damage_list = ReadIntArray();

        var damage_total = sp_damage_list.OrderByDescending(_ => _).Take(sp_types).Sum();
        Console.WriteLine(hp > damage_total ? "No" : "Yes");
    }

    static string[] ReadStringArray()
    {
        return Console.ReadLine().Split(' ');
    }

    static int[] ReadIntArray()
    {
        return ReadStringArray().Select(_ => int.Parse(_)).ToArray();
    }
}
 

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

using namespace std;
using ll = long long;

template <typename K,typename V>
using umap = unordered_map<K,V>;
template <typename V>
using uset = unordered_set<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 (b<a) { a=b; return 1; } return 0; }
#define REP(i,n) for(int i=0;i<n;i++)
#define REPD(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(v) v.begin(),v.end()

#define endl "\n"
#define INF 1'000'000'000'000 //10^12
#define MOD 1'000'000'007
//グリッドグラフの範囲チェック
bool range_validation(int y,int x,int h,int w){
    return y>=0 && y<h && x>=0 && x < w;
}
//ビットカウント
int popcount(long bits){
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

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

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);

  int n;
  cin >> n ;
  vector<int> a(n),b(n),c(n);
  REP(i,n)cin >> a[i] >> b[i] >> c[i];

  vector<vector<ll>> dp(n+1,vector<ll>(3,0));

  
  REP(i,n){
    dp[i+1][0] = max(dp[i][1],dp[i][2]) + a[i];

    dp[i+1][1] = max(dp[i][0],dp[i][2]) + b[i];

    dp[i+1][2] = max(dp[i][0],dp[i][1]) + c[i];
  }

  cout << max(dp[n][0],max(dp[n][1],dp[n][2])) << endl;

  return 0;
}


Measured memory_bytes: 9784
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
int main()
{
  ios_base::sync_with_stdio(0);
  ll n,m;
  cin >> n >> m;
  ll answer=0;
  if(n>=m)
  {
    ll x = m/2;
    answer = x;
  }
  else
  {
    ll y = n*2;
    if(m>=y)
    {
      answer+=n;
      m-=y;
      if(m>0)
      {
        ll temp = m/4;
        answer+=temp;
      }
    }
    else
    {
      ll blah = m/2;
      if(blah>n)
        answer=n;
      else
        answer = blah;
    }
  }
  cout << answer << endl;
  return 0;
}


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

#define all(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;

using Graph = vector<vector<int>>;
vector<bool> seen;
void dfs(const Graph &g, int v, P<int, int> &p){
    seen[v] = true;
    for(auto next_v : g[v]){
        if(seen[next_v]) continue;
        if(v == p.first && next_v == p.second) continue;
        if(v == p.second && next_v == p.first) continue;
        dfs(g, next_v, p);
    }
}

int main() {
    int n, m; cin >> n >> m;
    Graph g(n + 1);
    V<P<int, int> > p;
    for(int i = 0; i < m; i++){
        int a, b; cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
        p.push_back({a, b});
    }

    seen.resize(n);
    int cnt = 0;
    for(int i = 0; i < m; i++){
        dfs(g, 1, p[i]);
        for(int i = 1; i <= n; i++){
            if(!seen[i]){
                cnt++;
                break;
            }
        }
        for(int i = 1; i <= n; i++) seen[i] = false;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
chomp (my $n = readline ARGV);
chomp (my $s = readline ARGV);

my (@w, @e);
my $w = my $e = 0;
for my $i (0 .. $n - 1) {
  my $j = $n - 1 - $i;
  $w[$i] = $w;
  $e[$j] = $e;
  $w++ if substr($s, $i, 1) eq 'W';
  $e++ if substr($s, $j, 1) eq 'E';
}

my $min = $n;
for my $i (0 .. $n - 1) {
  my $r = $w[$i] + $e[$i];
  $min = $r if $r < $min;
}

print "$min\n";

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

int main(){
  int n;
  cin >> n;
  double x[n];
  string y[n];
  for(int i=0;i<n;i++){
    cin >> x[i] >> y[i];
  }
  double ans=0;
  for(int i=0;i<n;i++){
    if(y[i]=="JPY"){
      ans+=x[i];
    }
    else{
      ans+=x[i]*380000;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256