akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;
typedef pair<int,int> P;

vector<int> num = {0,2,5,5,4,5,6,3,7,6};

string maxs(string S, string T){
    if(S.length() > T.length()){
        return S;
    } else if (S.length() < T.length()){
        return T;
    } else {
        return (S < T) ? T : S;
    }
}

int main(){
    int N, M; vector<int> A(9);

    cin >> N >> M;
    rep(i,M) cin >> A[i];

    // dp[i]: マッチちょうどi本で作れる最大値
    vector<string> dp(10010, "");
    rep(i,N) rep(j,M){
        if(dp[i] == "" && i != 0) continue;

        char c = A[j] + '0';
        if(i+num[A[j]] <= N){
            string next = dp[i] + c;
            dp[i+num[A[j]]] = maxs(dp[i+num[A[j]]], next);
        }
    }

    cout << dp[N] << endl;
}


Measured memory_bytes: 43648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
ll kai[200005];

ll gcd(ll a, ll b){return b ? gcd(b,a%b):a;}
ll mkai(int n){
  if(n==0) return kai[0]=1;
  if(n%2) return kai[n]=mkai(n/2)*mkai(n/2)*2%MOD;
  else return kai[n]=mkai(n/2)*mkai(n/2)%MOD;
}

int main(){
  int n;
  cin >> n;
  map<P, int> mp;
  ll mp00=0;
  for(int i=0; i<n; ++i){
    ll a, b;
    cin >> a >> b;
    if(a<0){a*=-1; b*=-1;}
    if(a==0 && b == 0) ++mp00;
    else if(b==0) ++mp[make_pair(1,0)];
    else if(a==0) ++mp[make_pair(0,-1)];
    else if(b<0){b*=-1; ++mp[make_pair(a/gcd(a,b),b/gcd(a,b)*(-1))];}
    else ++mp[make_pair(a/gcd(a,b),b/gcd(a,b))];
  }
  ll ans=1;
  for(auto [ab,value]:mp){
    ll a=ab.first, b=ab.second;
    P np;
    if(b<0) np= make_pair(b*(-1),a);
    else np= make_pair(b,a*(-1));
    //cout << a << " " << b << " " << value << endl;
    //cout << mkai(value) << " " << mkai(mp[np]) << endl;
    ans *= (mkai(value) +mkai(mp[np])-1)%MOD;
    mp.erase(np);
    ans %= MOD;
    //cout << ans << endl;
  }
  ans += mp00 %MOD;
  ans -= 1;
  if(ans<0) ans += MOD;
  cout << ans << endl;
}

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

using namespace std;

int main()
{
    int m,d,x;
    int count=0;
    cin>>m>>d;

    for(int i=1;i <= m;i++)
    {
        for(int j=1;j <= d;j++)
        {
          x = j/10;
          if(j%10 >= 2)
          {
           if(x >= 2)
           {
             if(j%10*x == i)
             count++;
           }
          }
        }
    }

    cout<<count<<endl;

    return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int ans=1;
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		ans+=min(ans,k);
	} 
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
n,w=map(int,input().split())
wv=[list(map(int,input().split())) for i in range(n)]
wv.sort(key=lambda x:-x[1])#reverse
wv.sort(key=lambda x:x[0])
#print(wv)
w0=wv[0][0]
x=[[0],[0],[0],[0]]
for i in range(n):
    z=wv[i][0]-w0
    k=wv[i][1]+x[z][-1]
    l=len(x[z])
    if l*wv[i][0]<=w:
        x[z].append(k)
ma=0
l3=len(x[3])
l2=len(x[2])
l1=len(x[1])
l0=len(x[0])
for i in range(l3):
    for j in range(l2):
        d=w-i*(w0+3)-j*(w0+2)
        if d>=0:
            for k in range(l1):
                d=w-i*(w0+3)-j*(w0+2)-k*(w0+1)
                if d>=0:
                    m=min(d//w0,l0-1)
                    ma_sub=x[3][i]+x[2][j]+x[1][k]+x[0][m]
                    ma=max(ma,ma_sub)
                else:
                    break
        else:
            break

print(ma)


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

#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i, m, n) for(int i = (int)m; i < (int)n; i++)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;


/*FUNCs=================================================*/



/*MAIN==================================================*/
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化

    int n; cin >> n;
    vi a(n+1, 0);
  	rep2(i, 1, n+1){
      	int p;
      	cin >> p;
      	a[i] = p;
    }
    int cnt = 0, i = 1;
    while(cnt < n){
        i = a[i];
        cnt++;
        if(i == 2) break;
    }
    if(cnt == n) cnt =-1;
    cout << cnt <<endl;
}


Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
using namespace std;
int _P=1000000007;
int main(){
	long long a;
	string x;
	int c;
	cin >> a >> x;
	c = 10*(x[2]-'0')+x[3]-'0';
	cout << a*(x[0]-'0') + a*c/100 << endl;
	return 0;
}


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

int n, m, s, g, V, P;

int main()
{
    scanf("%d%d", &n, &m);
    vector<vector<int>> K(n, vector<int>(n, INF));
    rep(i, m)
    {
        int a, b, c, d;
        scanf("%d,%d,%d,%d", &a, &b, &c, &d);
        K[a - 1][b - 1] = c;
        K[b - 1][a - 1] = d;
    }
    scanf("%d,%d,%d,%d", &s, &g, &V, &P);
    rep(k, n) rep(i, n) rep(j, n)
    {
        if (K[i][j] > K[i][k] + K[k][j])
            K[i][j] = K[i][k] + K[k][j];
    }
    int ans;
    ans = V - P - K[s - 1][g - 1] - K[g - 1][s - 1];
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 3272
n = int(input())
A = list(map(int,input().split()))
dp = [0]*n
for i in range(n):
    dp[A[i]-1] += 1
sub = 0
for i in range(n):
    if dp[i] != 0:
        sub += dp[i]*(dp[i]-1)//2
for i in range(n):
    ans = sub
    k = A[i]
    ans -= dp[k-1]*(dp[k-1]-1)//2
    if dp[k-1] == 1:
        print(ans)
    else:
        print(ans+(dp[k-1]-1)*(dp[k-1]-2)//2)


Measured memory_bytes: 90060
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner stdin = new Scanner(System.in);
        int n = stdin.nextInt();
        int m = (n % 2 == 0) ? n / 2 : n / 2 + 1;
        System.out.println((double)m / n);
    }
}


Measured memory_bytes: 23764
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())
 
n = ni()
grid = []
 
for _ in range(n):
    s = ns()
    s = s+s
    grid.append(s)
    
for i in range(n):
    grid.append(grid[i])
    
vert = []
hrzn = []
 
for i in range(2*n):
    hrzn.append(grid[i])
    
for j in range(2*n):
    temp = ""
    for i in range(2*n):
        temp += grid[i][j:j+1]
        
    vert.append(temp)
    
    
ans = 0
b = 0 

for a in range(n):
        
    ok = True
    for i in range(n-1):
 
        if vert[b+i][a+i:a+n] != hrzn[a+i][b+i:b+n]:
            ok = False
            break
            
    if ok:
        ans += 1
            
print(ans*n)

Measured memory_bytes: 43356
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;

#define rep(i, a, b) for (int (i)=(a);(i)<=(b);(i)++)
#define Rep(i, a, b) for (int (i)=(a)-1;(i)<(b);(i)++)
#define REP(i, a, b) for (int (i)=(a);(i)>=(b);(i)--)
#define reg(i, x) for (int (i)=head[x];(i);i=e[i].next)
#define clr(a) memset(a,0,sizeof(a))
#define Sort(a, len) sort(a + 1, a + len + 1)
#define Sort2(a, len, cmp) sort(a + 1, a + len + 1, cmp)
#define ass(a, sum) memset(a, sum, sizeof(a))

#define ull unsigned long long
#define ll long long
#define ls ((rt) << 1)
#define rs ((rt) << 1 | 1)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'
#define Pii pair<int, int>

const int N = 100010 ;
const int iinf = INT_MAX/2 ;
const ll linf = LLONG_MAX/2 ;
const int MOD = 1e9+7 ;

inline int read(){
    int X = 0,w = 0 ;
	char ch = 0;
    while(!isdigit(ch)) {w |= ch == '-';ch = getchar();}
    while(isdigit(ch)) X = (X<<3) + (X<<1) + (ch ^ 48),ch = getchar();
    return w ? -X : X;
}

void write(int x){
     if(x < 0) putchar('-'),x = -x;
     if(x > 9) write(x / 10);
     putchar(x%10 + '0');
}

void print(int x) {
	cout << x << endl ;
	exit(0) ;
}

void douout(double x){
	 printf("%lf\n", x + 0.0000000001) ;
}

int n, m ;

int main(){
	scanf("%d%d", &n, &m) ;
	int tot = m / n ;
	for (int i = tot; i >= 1; i--) if (m % i == 0) print(i) ;
}

/*
写代码时请注意：
	1.是否要开Long Long？数组边界处理好了么？
	2.特殊情况处理好了么？
	3.做一些总比不做好。
	4.最大值和最小值问题可不可以用二分答案？
	5.有没有贪心策略？否则能不能dp？
	6.实数精度有没有处理？
*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  ll N;
  cin>>N;
vector<ll> P(N);
  for(ll i=0;i<N;i++) {
cin>>P[i];
  }
  ll m=P[0];
  ll ans=1;
  for(ll i=1;i<N;i++) {
if(m>=P[i]) {
ans++;
}
    m=min(m,P[i]);
  }
  
  cout<<ans<<endl;
}
  
  


Measured memory_bytes: 4804
# 隣二つ影響しか受けない

N = int(input())
A = list(map(int, input().split()))

M = 0
for i in reversed(A[::2]):
    M += i

for i in reversed(A[1:N:2]):
    M -= i
ans = [0] * N
ans[0] = M

for i in range(1,N):
    ans[i] = 2 * (A[i-1] - ans[i-1] // 2)

print(" ".join(map(str, ans)))

Measured memory_bytes: 19844
#include <bits/stdc++.h>
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
using namespace std;

int64_t f(int64_t x)
{
    if(x==1)return 1;
    return x*f(x-1)%1000000007;
}

int main()
{
    int64_t n,m;
    cin>>n>>m;
    int64_t s=f(min(n,m));
    s=s*s%1000000007;
    if(abs(n-m)>=2)cout<<0<<endl;
    if(abs(n-m)==1)cout<<s*max(n,m)%1000000007<<endl;
    if(m==n)cout<<s*2%1000000007<<endl;
}


Measured memory_bytes: 1792
N = int(input())
inf = float("inf")
dp = [inf for _ in range(N+1)]
l6 = 7
l9 = 6
dp[0] = 0

# DP
for i in range(1, N+1):
    # 1円を引き出す
    dp[i] = min(dp[i], dp[i-1] + 1)
    
    # 6の累乗円を引き出す
    for j in range(1, l6):
        if i - 6**j >= 0:
            dp[i] = min(dp[i], dp[i - 6**j] + 1)
        
    # 9の累乗円を引き出す
    for j in range(1, l9):
        if i - 9**j >= 0:
            dp[i] = min(dp[i], dp[i - 9**j] + 1)

print(dp[N])

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

int main(){

  bool d;
  string s;

  while(true){
    cin >> s;
    if(s == "0000") break;

    int ans = 0;
    while(s != "6174"){
      string a = s,b;

      d = true;
      for(int i=0;i<3;i++){
	if(s[i] != s[i+1]) d = false;
      }

      if(d) break;

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

      int n = 0,m = 0;
      for(int i=0;i<4;i++){
	n *= 10;
	m *= 10;
	n += a[i] - '0';
	m += b[i] - '0';
      }

      m -= n;

      int k = 1000;
      s = "";

      for(int i=0;i<4;i++){
	s += (m/k + '0');
	m -= m/k * k;
	k /= 10;
      }

      ans++;
    }

    if(d) cout << "NA" << endl;
    else cout << ans << endl;

  }
}

Measured memory_bytes: 1216
import java.util.Arrays;
import java.util.Scanner;

class Main {
    public static void main(final String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int a = 0;
        int b = 0;
        int i = 0;

        boolean flag = true;
        while (flag) {
            for (int j = 0; j <= i; j++) {
                if (Math.pow(i, 5) - Math.pow(j, 5) == x) {
                    a = i;
                    b = j;
                    flag = false;
                    break;
                }
                if (Math.pow(i, 5) - Math.pow(j * -1, 5) == x) {
                    a = i;
                    b = j * -1;
                    flag = false;
                    break;
                }
            }
            i++;
        }
        
        System.out.println(a + " " + b);
    }
}


Measured memory_bytes: 38664
#include <bits/stdc++.h>  // include all standard C++ libraries

using namespace std;

// Loops
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define _rrep(i,n) rrepi(i,n,0)
#define rrepi(i,a,b) for(int i=int(a)-1;i>=int(b);--i)

#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(xi, x) for (auto&& xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)


// typedef
using ll = long long;
template <class T> using vec = vector<T>;
using vi   = vector<int>;
using vvi  = vector<vi>;
using vvvi = vector<vvi>;
using pii  = pair<int, int>;


// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second


// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase( unique(all(v)), v.end() )
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<class T> pair<T, size_t> max(vector<T> &x){ auto it = max_element(all(x)); return mp(*it, it-x.begin()); }
template<class T> pair<T, size_t> min(vector<T> &x){ auto it = min_element(all(x)); return mp(*it, it-x.begin()); }

template<class T> inline bool chmax(T &maxval, const T &newval) { if (maxval<newval) { maxval=newval; return 1; } return 0; }
template<class T> inline bool chmin(T &minval, const T &newval) { if (minval<newval) { minval=newval; return 1; } return 0; }

// Utilities
// Grid world utilities
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
#define inside(H,W,y,x) 0<=(x) && (x)<(W) && 0<=(y) && (y)<(H)

inline int in() {int x; cin >> x; return x;} // read int from cin
inline  ll IN() {ll x; cin >> x; return x;}  // read ll from cin



// Debug
#ifdef LOCAL
  #include "dump.hpp"
  #define debug(x) cerr << #x << ": " << x << '\n'
#else
  #define dump(...)
  #define debug(x)
#endif

// Paste snippets here!!

// 

int main(){
  cin.tie(0); ios::sync_with_stdio(false);    // Magic for faster cin
  int A=in(); int B=in();
  int g=0;
  if(A>B) {g += A; A--;}
  else {g+=B; B--;}
  if(A>B) {g += A; A--;}
  else {g+=B; B--;}
  cout << g << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#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 llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll,ll> pll;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define MOD 1000000007
#define ARRAY_MAX 100005

const int INF = 1e9+7;


int main(){

    int n;
    while(cin >> n,n){
        vector<pii> a(n);
        for(int i = 0;i < n;i++){
            cin >> a[i].second >> a[i].first;
        }
        sort(a.begin(),a.end());
        int cnt = 0;
        bool ans = true;
        for(int i = 0;i < n;i++){
            if(cnt + a[i].second > a[i].first){
                ans = false;
                break;
            }else{
                cnt += a[i].second;
            }
        }
        if(ans){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3004
#include <algorithm>
#include <iostream>
using namespace std;
static const int MAX = 200000;

int main()
{
    int R[MAX], n;

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

        int maxv = -2000000000;
        int minv = R[0];
   

    for (int i = 1; i < n; i++)
    {
        maxv = max(maxv, R[i] - minv);
        minv = min(minv, R[i]);
    }

    cout << maxv << endl;

    return 0;
}

Measured memory_bytes: 3860
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    // Here your code !
    long long int N,A,B,C,hiC,loC,sum;
    cin >> N >> A >> B;
    vector <long long int> H(N);
    vector<long long int> Ht(N);
    for(int i=0;i<N;i++){
        
        cin >> H[i];
        
    }
    
    sort(H.begin(),H.end());
    
    C=H[N-1]/B;
    hiC=C;
    loC=0;
    while(1){
        sum=0;
        for(int i=0;i<N;i++)
        {
            
            Ht[i]=H[i]-C*B;
            if(Ht[i]>0){
                sum+=(Ht[i]+A-B-1)/(A-B);
           }
           
           
        }
        if(sum == C){
            cout << C << "\n";
            return 0;
        }
        if(sum>C)
        {
            loC=C;
            C+=(hiC-loC)/2;
        }else
        {
            hiC=C;
            C-=(hiC-loC)/2;
            
               
        }
        if(hiC-loC==1){
           
            cout << hiC << "\n";
            return 0;   
        }
        if(hiC-loC==0){
            
            cout << hiC+1<<"\n";
            return 0;
        }
        
        
        
    
    }
    
    return 0;
    
}


Measured memory_bytes: 1792
mycode = r'''
# distutils: language=c++
# cython: language_level=3, boundscheck=False, wraparound=False
# cython: cdivision=True
# False:Cython はCの型に対する除算・剰余演算子に関する仕様を、(被演算子間の符号が異なる場合の振る舞いが異なる)Pythonのintの仕様に合わせ、除算する数が0の場合にZeroDivisionErrorを送出します。この処理を行わせると、速度に 35% ぐらいのペナルティが生じます。 True:チェックを行いません。

ctypedef long long LL

cdef extern int __builtin_popcount(unsigned int) nogil

import numpy as np

import sys
readline = sys.stdin.buffer.readline
read = sys.stdin.readline #文字列読み込む時はこっち


cdef ints(): return np.fromstring(readline(), sep=' ', dtype=np.int64)


cdef read_matrix(LL H,LL W):
    #return np.ndarray shape=(H,W) matrix
    lines=[]
    cdef LL _
    for _ in range(H): 
        lines.append(read())
    lines=' '.join(lines) #byte同士の結合ができないのでreadlineでなくreadで
    return np.fromstring(lines, sep=' ',dtype=np.int64).reshape(H,W)

# この問題をあえてグラフの構造を持つことで解く
from libcpp.vector cimport vector as vec

cdef LL N,M
N,M=ints()
AB=read_matrix(M,2)-1
cdef LL a,b

ctypedef vec[vec[LL]] Graph
cdef Graph graph=Graph(N)

for a,b in AB:
    graph[a].push_back(b)
    graph[b].push_back(a)

cdef vec[int] ans
for i in range(N):
    ans.push_back(graph[i].size())
print(*ans, sep='\n')
'''

import sys
import os
if sys.argv[-1] == 'ONLINE_JUDGE':  # コンパイル時
    with open('mycode.pyx', 'w') as f:
        f.write(mycode)
    os.system('cythonize -i -3 -b mycode.pyx')

import mycode


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

using namespace std;
typedef long long ll;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define each(i,mp) for(auto& i:mp)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;
const ll m=1LL<<32;

int main(){

  ll n;cin>>n;
  string s;cin>>s;
  ll left=0;
  ll right=0;
  string ans="";

  rep(i,0,n){
    if(s[i]=='('){
      left++;
      ans.insert(ans.end(),'(');
    }else{
      ans.insert(ans.end(),')');
      if(left==0)ans.insert(ans.begin(),'(');
      left=max((ll)0,left-1);
    }
  }
  rep(i,0,left)ans.insert(ans.end(),')');
  out(ans);

  return 0;
}


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

using ll=long long;

int main() {
  int n; cin >>n;
  deque<int> ans;
  rep_eq(i,1,n) {
    int a; cin >>a;
    int temp1=i%2;
    int temp2=n%2;
    if (temp1==temp2) {
      ans.push_front(a);
    } else {
      ans.push_back(a);
    }
  }
  rep(i,0,ans.size()) {cout <<ans[i] <<' ';}
  return 0;
}


Measured memory_bytes: 4436
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
void cxxio() {
    ios::sync_with_stdio(false);
    cin.tie(0);
}
#define ss second

int main() {
    cxxio();
    int n, m;
    cin>>n>>m;
    map<int, int> cnt;
    for (int a, b; cin>>a>>b;) {
        cnt[a]++;
        cnt[b]++;
    }
    for (pii p:cnt)
        if (p.ss%2)
            return cout<<"NO\n", 0;
    cout<<"YES\n";
}


Measured memory_bytes: 4352
from sys import stdin, setrecursionlimit
#input = stdin.buffer.readline
setrecursionlimit(10 ** 7)

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi, radians, sin, cos

MOD = 10 ** 9 + 7
INF = 10 ** 6

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

cnt = defaultdict(int)
cnt_h = defaultdict(int)
cnt_w = defaultdict(int)

for h, w in hw:
    cnt[h * INF + w] += 1
#print(cnt)

for h, w in hw:
    cnt_h[h] += 1
    cnt_w[w] += 1
cnt_h = list(cnt_h.items())
cnt_w = list(cnt_w.items())
cnt_h.sort(key = lambda x: -x[1])
cnt_w.sort(key = lambda x: -x[1])
#print(cnt_h)
#print(cnt_w)

max_h = []
max_w = []
for h, n in cnt_h:
    if n == cnt_h[0][1]:
        max_h.append(h)
for w, n in cnt_w:
    if n == cnt_w[0][1]:
        max_w.append(w)
#print(max_h)
#print(max_w)

answer = cnt_h[0][1] + cnt_w[0][1]
for mh in max_h:
    for mw in max_w:
        if cnt[mh * INF + mw] == 0:
            print(answer)
            exit()
print(answer - 1)

Measured memory_bytes: 216988
n = input()
ans = 0
if 1 <= int(n[0:2]) <= 12 and 0 <= int(n[2:4]) <= 99:
  ans += 1
if 0 <= int(n[0:2]) <= 99 and 1 <= int(n[2:4]) <= 12:
  ans += 3
if ans == 1:
  print('MMYY')
elif ans == 3:
  print('YYMM')
elif ans == 4:
  print('AMBIGUOUS')
else:
  print('NA')

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

int main() {
  int N;
  cin >> N;
  vector<pair<int,int>> V(N);
  for(int i=0;i<N;i++){
    int x,l;
    cin >> x >> l;
    V[i].first = x+l;
    V[i].second = x-l;
  }
  sort(V.begin(),V.end());
  
  int ans=0,now=-1001001001;
  for(int i=0;i<N;i++){
    if(V[i].second>=now){
      ans++;
      now = V[i].first;
    }
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
#include <climits>
#include <chrono>
#include <fstream>
using namespace std;

#pragma region

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

const double PI = acos(-1.0);

using ll = long long;
using P = pair<int, int>;

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; }

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter = " ") { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

#pragma endregion


int main() {
    int n, m;
    string s;
    cin >> n >> m >> s;
    
    vector<int> last_0(n);
    int l = n;
    revrep(i, n) {
        if (s[i] == '0') l = i;
        last_0[i] = l;
    }
    
    int pos = n;
    vector<int> ans;
    while (1) {
        if (pos == 0) break;
        
        int nxt = last_0[max(0, pos - m)];
        if (nxt == pos) {
            cout << -1 << endl;
            return 0;
        }
        ans.push_back(pos - nxt);
        pos = nxt;
    }
    reverse(ans.begin(), ans.end());
    print(ans);
}

Measured memory_bytes: 4376
#include <iostream>
using namespace std;
const long long MOD = 1e9+7;
//aのMODbでの逆元
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int main(){
    long long n;
    cin >> n;
    long long a[n+1];
    long long fl[n+1];
    fill_n(fl,n+1,-1);
    long long dif;
    for(int i = 0;i<n+1;i++){
        cin >> a[i];
        if(fl[a[i]]==-1) fl[a[i]]=i;
        else dif = i-fl[a[i]]; 
    }
    dif = n-dif;
    long long combi1 = n+1;
    long long combi2 = 1;
    long long ans[n+1];
    for(int i = 0;i<n+1;i++){
        ans[i]=combi1-combi2;
        combi1*=(n-i);
        combi1%=MOD;
        combi1*=modinv(i+2,MOD);
        combi1%=MOD;
        combi2*=(dif-i);
        combi2%=MOD;
        combi2*=modinv(i+1,MOD);
        combi2%=MOD;
        ans[i]%=MOD;
        if(ans[i]<0) ans[i]+=MOD;
    }
    for(int i = 0;i<n+1;i++) cout << ans[i] << endl;
}

Measured memory_bytes: 3584
# サイクル検出
import sys
sys.setrecursionlimit(10**7) 

def dfs(G, v, p):
    global pos
    seen[v] = True
    hist.append(v)
    for nv in G[v]:
        # 逆流を禁止する
        if nv == p:
            continue

        # 完全終了した頂点はスルー
        if finished[nv]:
            continue

        # サイクルを検出
        if seen[nv] and not finished[nv]:
            pos = nv
            return
        
        # 再帰的に探索
        dfs(G, nv, v)

        # サイクル検出したならば真っ直ぐに抜けていく
        if pos != -1:
            return 
    hist.pop()
    finished[v] = True

# 頂点数 (サイクルを一つ含むグラフなので辺数は N で確定)
N = int(input())

# グラフ入力受取
G = [[] for _ in range(N)]
for i in range(N):
    a,b = map(int, input().split())
    # 頂点番号が 1-indexed で与えられるので 0-indexed にする
    a-=1
    b-=1
    G[a].append(b)
    G[b].append(a)

# 探索
seen = [False]*N
finished = [False]*N
pos = -1
hist = []
dfs(G, 0, -1)

# サイクルを復元
cycle = set()
while len(hist):
    t = hist.pop()
    cycle.add(t)
    if t == pos:
        break

# クエリに答える
Q = int(input())
for _ in range(Q):
    a,b = map(int, input().split())
    a-=1
    b-=1
    if a in cycle and b in cycle:
        print(2)
    else:
        print(1)


Measured memory_bytes: 128672
#include<bits/stdc++.h>
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main() {

    jaldi

    int n;
    cin>>n;
    vector<int> arr(n);
    for(int i=0;i<n;i++) {
        cin>>arr[i];
    }
    int count = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            for (int k = j + 1; k < n; k++) {
                if (arr[i] == arr[j] || arr[j] == arr[k] || arr[k] == arr[i]) {
                    continue;
                } else {
                    if (
                            arr[i] + arr[j] > arr[k]
                            && arr[i] + arr[k] > arr[j]
                            && arr[k] + arr[j] > arr[i])
                        count++;
                }
            }
        }
    }

    cout<<count<<'\n';
}


Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, a[280000] = {}, z = 0;
    cin >> n;
    for (int i = 0; i < (1 << n); i++) cin >> a[i];
    for (int i = 1; i < (1 << n); i++) {
        vector<int> b;
        for (int j = 0; j < n; j++) if (i & (1 << j)) b.push_back(j);
        int m = (int)b.size(), d[18] = {}, c = 0, x = a[0], y = 0;
        for (int j = 1; j < (1 << m); j++) {
            int e = __builtin_ctz(j);
            if (!d[e]) d[e] = 1, c += 1 << b[e];
            else d[e] = 0, c -= 1 << b[e];
            if (a[c] > x) y = x, x = a[c];
            else if (a[c] > y) y = a[c];
        }
        z = max(z, x + y);
        cout << z << '\n';
    }
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,b,a) for(ll i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< ll, ll >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)
const ll INF=1e17;
using namespace std;
void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
void  solve(){
  // ll n,k;
  // cin>>n>>k;
  // ll a[n];
  // rep(i,0,n) cin>>a[i];
  // vector<ll> dp1(60,0);
  // vector<vector<ll>> dp(n,vector<ll>(60,0));
  //
  // ll temp=k;
  // ll idx1=0;
  // while(temp){
  //   if(temp%2) dp1[idx1]++;
  //   idx1++;
  //   temp=temp/2;
  // }
  //
  // rep(i,0,n){
  //   ll temp=a[i];
  //   int idx=0;
  //   while(temp){
  //     if(temp%2) dp[i][idx]++;
  //     idx++;
  //     temp=temp/2;
  //   }
  // }
  //
  // ll idx=0;
  // rep(j,0,60){
  //   rep(i,0,n) if(dp[i][j]) idx=j;
  //   if(dp1[j]) idx=max(idx,j);
  // }
  //
  // ll num=0;
  // ll ans=0;
  // auto comp =[](pii &x , pii &y){
  //   if(x.f==y.f) return x.s<y.s;
  //   return x.f>y.f;
  // };
  // // sort(a,a+n,comp);
  // priority_queue<pii,std::vector<pii> ,decltype(comp)> pq(comp);
  // rrep(j,idx,0){
  //   ll c=0;
  //   rep(i,0,n) if(dp[i][j]) c++;
  //
  //   if(c*2<n){
  //     if(num+pow(2LL,j) <=k){
  //       // num+= pow(2LL,j);
  //       ll left=(n-c)*pow(2LL,j);
  //       pq.push({left,pow(2LL,j)});
  //       // ans+= c*pow(2LL,j);
  //     }
  //     else ans+= c*pow(2LL,j);
  //   }
  //   else ans+= c*pow(2LL,j);
  // }
  // while(!pq.empty()){
  //   cout<<pq.top().f<<" "<<pq.top().s<<endl;
  //   pq.pop();
  // }
  // cout<<ans<<endl;

  ll n,k;
     cin>>n>>k;
     ll a[n];
     for(int i=0;i<n;i++)cin>>a[i];
     int ct[n][60];
     memset(ct,0,sizeof(ct));
     for(int i=0;i<n;i++){
          ll t=a[i];
          for(int j=0;j<50;j++){
               ct[i][j]=t%2;
               t/=2;
          }
     }
     ll res=0LL,tmp=0LL;
     for(int j=59;j>=0;j--){
          int count1=0;
          for(int i=0;i<n;i++){if(ct[i][j]==1)count1++;}
          if(count1>=n-count1){
               res+=count1*(1LL<<j);
          }
          else{
               ll ty=(tmp+(1LL<<j));
               if(ty<=k){
                    tmp=ty;
                    res+=(n-count1)*(1LL<<j);
               }
               else{
                    res+=(count1)*(1LL<<j);
               }
          }
     }
     cout<<res;
}
int main(){
    optimizeIO();
    { solve();
    }
}


Measured memory_bytes: 27880
//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

int main()
{
    #ifndef ONLINE_JUDGE
    if (fopen("INPUT.txt", "r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        //freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    clock_t clk;
    clk = clock();
//-----------------------------------------------------------------------------------------------------------//

    READV(K);
    READV(A);
    READV(B);
    if(B/K==(A-1)/K)
    {
        cout<<"NG"<<endl;
    }
    else
    {
        cout<<"OK"<<endl;
    }
    

//-----------------------------------------------------------------------------------------------------------//


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

    return 0;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

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

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

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

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

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

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}
void solve(int k){
  ll res = 0;
  REP(i,1,sqrt(k)+1){
    if(k % i == 0 && k != i){
      res += i;
      if(i != k/i && k/i != k){
        res += k/i;
      }
    }
  }
  string s[3] = {"deficient number","abundant number","perfect number"};
  if(k == res) cout << s[2] << endl;
  else if(k < res) cout << s[1] << endl;
  else cout << s[0] << endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  while(cin >> n && n){
    solve(n);
  }
  return 0;
}

Measured memory_bytes: 3036
#include <bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define lmt 600001
int _I(){int x; scanf("%d",&x); return x;}
bool prime[lmt+5];
vector< long > pp;
void seive(){
    //int i,j;
    pp.push_back(2);
    for(long i = 4; i <= lmt; i+=2) prime[ i ] = 1;
    for(long i = 3; i <= lmt; i+=2){
        if(!prime[ i ]){
            pp.push_back(i);
            for(long j = i*3; j <= lmt; j+=i<<1) prime [ j ] = 1;
        }
    }
    prime[0]=prime[1]=1;
}
int ar[ 101 ],n,ans = INT_MAX;
int f(int l,int h){
    if(l>h) return ans;
    int cst = 0;
    for(int i = 0; i <n; i++ ){
        cst+=((ar[i]-l)*(ar[i]-l));
    }
    ans=min(ans,cst);
    f(l+1,h);
}
void Lipu_mira()
{
    n = _I();
    for( int i = 0; i < n; i++) ar[ i ] = _I();
    sort(ar,ar+n);
    printf("%d\n",f(ar[0],ar[n-1]));
}
int main()
{
    //seive();
    //while(true)
    Lipu_mira();
    return 0;
}


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

typedef long long ll;

int main() {
    ll N, MOD = 1e9 + 7, x = 1, y = 1, z = 1;
    cin >> N;
    rep(i, N) {
        x = (x * 10) % MOD;
        y = (y * 9) % MOD;
        z = (z * 8) % MOD;
    }
    cout << (x - y - y + z + MOD + MOD) % MOD << "\n";
}

Measured memory_bytes: 3632
#include <stdio.h>

int main(){

  int i,n,H[250];
  scanf("%d",&n);

  for(i=1;i<=n;i++)scanf("%d",&H[i]);
  i=1;
    printf("node %d: key = %d, left key = %d, right key = %d, \n",i,H[i],H[i*2],H[i*2+1]);
    
  for(i=2;i<=n;i++){
    
    printf("node %d: key = %d, ",i,H[i]);

      if(i/2<=n)printf("parent key = %d, ",H[i/2]);
      
      if(i*2<=n)printf("left key = %d, ",H[i*2]);

      if(i*2+1<=n)printf("right key = %d, ",H[i*2+1]);

      printf("\n");
}

  return 0;
}



Measured memory_bytes: 2052
package main

import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  var line, buffer []byte
  var isPrefix bool = true
  var err error
  for isPrefix {
    line, isPrefix, err = reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
  }
  return string(buffer)
}
func NextIntVec() []int {
  L := strings.Split(NextLine(), " ")
  N := make([]int, len(L))
  for i := range N {
    N[i], _ = strconv.Atoi(L[i])
  }
  return N
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func Output() {
  _ = writer.Flush()
}

func main() {
  NM := NextIntVec()
  N := NM[0]
  M := NM[1]
  G := make([][]int, N)
  for i := range G {
    G[i] = make([]int, 0)
  }
  for i := 0; i < M; i++ {
    AB := NextIntVec()
    A := AB[0] - 1
    B := AB[1] - 1
    G[A] = append(G[A], B)
    G[B] = append(G[B], A)
  }
  D := make([]int, N)
  for i := 1; i < N; i++ {
    D[i] = N
  }
  Q := make([]int, N)
  pos := 1
  incomplete := true
  for i := 0; i < N && incomplete; i++  {
    s := Q[i]
    for _, adj := range G[s] {
      if D[adj] == D[s] {
        incomplete = false
        break
      }
      if D[adj] < N { continue }
      D[adj] = D[s] + 1
      Q[pos] = adj
      pos += 1
    }
  }
  cnt := N * (N - 1) / 2 - M
  if incomplete {
  	OE := []int{0, 0}
  	for _, d := range D {
      OE[d % 2] += 1
  	}
    cnt -= OE[0] * (OE[0] - 1) / 2 + OE[1] * (OE[1] - 1) / 2  
  }
  Write(cnt)
  Output()
}

Measured memory_bytes: 10752
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
#ifdef zerol
#define dbg(args...) do { cout << "\033[32;1m" << #args << " -> "; err(args); } while (0)
#else
#define dbg(...)
#endif
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... Args>
void err(T<t> a, Args... args) { for (auto x: a) cout << x << ' '; err(args...); }
template<typename T, typename... Args>
void err(T a, Args... args) { cout << a << ' '; err(args...); }
////////////////////////////////////////////////////////////////////////////////////

struct Edge { int to, c, id; };

const int N = 1E5 + 100;
vector<Edge> G[N], rG[N], H[N];
vector<int> orders;
const int S = 1, T = 2;
const LL INF = 1E15;
LL ds[N], dt[N];

struct HeapNode {
    LL d; int u;
    bool operator < (const HeapNode &x) const {
        return d > x.d || (d == x.d && u < x.u);
    }
};
void dijkstra(vector<Edge>* G, int s, int n, LL* dis) {
    static int done[N];
    memset(done, 0, sizeof done);
    fill(dis, dis + n + 1, INF);
    priority_queue<HeapNode> q;
    dis[s] = 0; q.push({0, s});
    while (!q.empty()) {
        HeapNode x = q.top(); q.pop();
        int u = x.u; if (done[u]) continue;
        done[u] = 1;
        for (Edge &e: G[u]) {
            if (!done[e.to] && dis[e.to] > dis[u] + e.c) {
                dis[e.to] = dis[u] + e.c;
                q.push({dis[e.to], e.to});
            }
        }
    }
}
int st[N], ed[N], wt[N], n, m;
int in[N], out[N], ans[N];

void toposort(int s) {
    static int dg[N];
    copy(in + 1, in + n + 1, dg + 1);
    assert (dg[s] == 0);
    queue<int> q; q.push(s); orders.push_back(s);
    while (!q.empty()) {
        int u = q.front(); q.pop();
        for (Edge &e: H[u]) {
            dg[e.to]--;
            if (dg[e.to] == 0) {
                orders.push_back(e.to);
                q.push(e.to);
            }
        }
    }
}

int main() {
    cin >> n >> m;
    FOR (i, 0, m) {
        int u, v, w; cin >> u >> v >> w;
        G[u].push_back({v, w, i});
        rG[v].push_back({u, w, i});
        st[i] = u; ed[i] = v; wt[i] = w;
    }
    dijkstra(G, S, n, ds);
    dijkstra(rG, T, n, dt);
    LL presumed = ds[T];
    // dbg(presumed);

    FOR (i, 0, m) {
        int u = st[i], v = ed[i], w = wt[i];
        if (ds[u] + w + dt[v] == presumed) {
            H[u].push_back({v, w, i});
            in[v]++; out[u]++;
            dbg(u, v, w);
        }
    }
    toposort(S);
    int ctr = 0;
    for (int u: orders) {
        ctr -= in[u];
        ctr += out[u];
        if (ctr == 1) {
            assert ((int) H[u].size() == 1);
            ans[H[u][0].id] = 1;
        }
    }

    FOR (i, 0, m) {
        int u = st[i], v = ed[i], w = wt[i];
        // dbg(u, v, ds[v], dt[u]);
        if (ds[v] + w + dt[u] < presumed) {
            puts("HAPPY");
        } else {
            if (ans[i]) puts("SAD");
            else puts("SOSO");
        }
    }
}


Measured memory_bytes: 24268
import sys
from collections import deque, Counter, defaultdict
from fractions import gcd
input = sys.stdin.readline

def eprint(s):
    if type(s) != type('str'):
        s=str(s)

    sys.stderr.write(s+'\n')
    return

def main():
    a = int(input())
    b = int(input())
    c = int(input())
    d = int(input())
    e = int(input())
    k = int(input())

    if max(a,b,c,d,e) - min(a,b,c,d,e) > k:
        print(':(')
    else:
        print('Yay!')
    return

if __name__ == '__main__':
    main()

Measured memory_bytes: 63980
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007;
struct edge {int to,costa,costb;};

signed main() {
 int n,m;
 cin>>n;
bool x[n+1];fill(x,x+n+1,true);
int ans=1,k;
for(int i=2;i<=n;i++){
    if(!x[i])continue;
    for(int j=2;j*i<=n;j++)x[i*j]=false;
    m=n;k=0;
    while(m){
        k+=m/i;
        m/=i;
    }
    ans=(ans*(k+1))%MOD;
}
cout<<ans;


return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <climits>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iostream>
#include <math.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define str string
#define deb_arr(arr,n) for(ll i=0;i<(n);i++){ cout << (arr)[i] << " ";}
#define in_arr0(arr,n) for(ll i=0;i<(n);i++){ cin >> (arr)[i]; }
#define in_arr1(arr,n) for(ll i=1;i<=(n);i++){ cin >> (arr)[i];}
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> pbds;
#define vll vector<ll> 
#define fr(n) for(i=0;i<(n);i++)
#define fr1(n) for(i=1;i<=(n);i++)
#define pll pair<ll,ll>
#define f first
#define s second
#define vpll vector<pll>
#define ump unordered_map
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define IN(a,b) ((a).find(b)!=(a).end())
#define pb push_back
#define mkp make_pair
#define PI M_PI
#define INF 1e18
#define deb(x) if(ON) cout << #x <<" : " << x << endl
#define fast ios_base::sync_with_stdio(false)
#define io cin.tie(NULL),cout.tie(NULL)
#define ON !false
ll dx[]={0,-1,0,1};
ll dy[]={1,0,-1,0};
const ll mod=1e9+7;
inline ll add(ll a,ll b){
    return  ((a%mod)+(b%mod)+mod)%mod;
}
inline ll mul(ll a,ll b){
    return ((a%mod)*(b%mod)+mod)%mod;
}
void pause(ll id){
    cout << "Waiting " << id << endl;
    cin >> id;
}

const int mxn=1e5+10;


void init(){

    return ;
}


signed main(){
    fast;
    io;
    if(!true){
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    }
    init();
    ll i,j;
    ll s,w;
    cin >> s >> w;
    if(w >= s){
        cout << "unsafe" << endl;
    }
    else{
        cout << "safe" << endl;
    }
   
    return 0;
}


Measured memory_bytes: 3612
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i < b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const long double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];

	int ma = *max_element(all(a));

	int half = ma;
	int idx = -1;
	rep(i, n) {
		if (a[i] == ma) continue;
		if (abs(ma / 2 - a[i]) < half) {
			half = abs(ma / 2 - a[i]);
			idx = i;
		}
	}

	cout << ma << " " << a[idx] << endl;

	return 0;
}

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

int isprime(int a, int b) {
    if(b == 2) {return true;}
    if(b > 2 && b % 2 == 0) {return false;}
    else {
        int i = 3;
        while(i <= sqrt(b)) {
            if(b % i == 0) return false;
            i = i + 2;
        }
        return true;
    }
}

int main() {
    int n, x, count = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &x);
        if (isprime(n,x)) count++;
    }
    printf("%d\n", count);
    
    return 0;
}


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

const ll mod = 1000000007;
const double eps = 1e-8;

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

vector<string> ans;
int N;

void dfs(int k, vector<int> &t, int mx) {
    if (k == N) {
        string s;
        for (int i=0; i<N; ++i) {
            s += char('a'+t[i]);
        }
        ans.push_back(s);
        return;
    }
    for (int i=0; i<=min(k, mx+1); ++i) {
        t.push_back(i);
        dfs(k+1, t, max(mx, i));
        t.pop_back();
    }
}

int main() {
    cin >> N;
    vector<int> t;
    dfs(0, t, -1);
    for (string s: ans) {
        cout << s << endl;
    }
    return 0;
}

Measured memory_bytes: 9588
'use strict'
function main(i) {
  i = i.trim().split('\n').map(n => Number(n))
  const N = i.shift()
  const j = [...i].sort((a, b) => b - a)
  console.log(i.map(n => n === j[0] ? j[1] : j[0]).join('\n'))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 48400