akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
    #include<algorithm>
    using namespace std;
    #define mod 1e9+7
    #define FOR(a,c)   for ( long long int (a)=0; (a)<(c); (a)++)
    #define FORL(a,b,c)  for ( long long int (a)=(b); (a)<=(c); (a)++)
    #define FORR(a,b,c)  for (  long long int (a)=(b); (a)>=(c); (a)--)
    #define INF 1000000000000000003
    typedef long long int ll;
    typedef vector<long long int> vi;
    typedef pair<long long int,long long int> pi;
    typedef priority_queue<long long int> max_pq;
    typedef priority_queue<long long int, vector<long long int>, greater<long long int>> min_pq;
    #define F first
    #define S second
    #define PB push_back
    #define POB pop_back
    #define MP make_pair
    #define pi 3.1415926535
    #define buff cin.ignore(numeric_limits<streamsize>::max(),'\n')

    // Use inbuilt function  __gcd(a,b), __builtin_popcount(n), Use (x&-x) for last set Bit;
    
    int main()
    {
        ios::sync_with_stdio(NULL);
        cin.tie(NULL);
        cout.tie(NULL);

        string x,y;
        cin>>x>>y;
        ll n=x.size(),m=y.size();

        ll dp[n+1][m+1];
        for(ll i=0;i<=n;i++)
        {
            for(ll j=0;j<=m;j++)
            {
                if(i==0 || j==0)
                    dp[i][j]=0;
                else if(x[i-1]==y[j-1])
                    dp[i][j]=dp[i-1][j-1]+1;
                else
                    dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
        ll idx = dp[n][m];
        char arr[idx+1];
        arr[idx]='\0';
        ll i=n,j=m;
        while(i>0 && j>0)
        {
            if(x[i-1]==y[j-1])
            {
                arr[idx-1]=x[i-1];
                i--;
                j--;
                idx--;
            }
            else if(dp[i-1][j]>dp[i][j-1])
                i--;
            else
                j--;
        }
        cout<<arr<<endl;

        return 0;
    }

Measured memory_bytes: 70656
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
import std.numeric;


void main() {
    int n, m;
    scan(n, m);

    auto adj = new int[][](n + m, 0);

    foreach (i ; 0 .. n) {
        auto line = readln.split.to!(int[]);

        foreach (lang ; line[1 .. $]) {
            lang += n - 1;
            adj[i] ~= lang;
            adj[lang] ~= i;
        }
    }

    auto visited = new bool[](n + m);

    void dfs(int u) {
        visited[u] = 1;

        foreach (v ; adj[u]) {
            if (!visited[v]) {
                dfs(v);
            }
        }
    }

    dfs(0);

    foreach (i ; 0 .. n) {
        if (!visited[i]) {
            writeln("NO");
            return;
        }
    }

    writeln("YES");
}



void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 12668
/** Author : dhakad_123
 * Created: 11.07.2020
 **/

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


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
     
        int l , r ,d;
	cin >> l >> r >> d;

	int ans = 0;

	for(int i = l; i <= r; i++){

		if(i % d == 0){
			ans++;
		}
	}
	cout << ans  << "\n";

	return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <limits.h>
#include <queue>
#include <algorithm>
#include <map>
#include <cstring>

#define dprintf(s,...) printf("%s:%d" s,__func__,__LINE__,__VA_ARGS__)
using namespace std;

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

int N;
vector<int> T;

int solve(){

  int ret=0,s=0;
  sort(T.begin(), T.end());
  
  for(int i=0;i<T.size();i++){
    s+=T[i];
    ret+=s;

  }
  return ret;
}

int main(){

  while(1){
    cin>>N;
    if(cin.eof()) break;
    for(int i=0;i<N;i++){
      int hoge;
      cin>>hoge;
      T.push_back(hoge);
    }
    cout<<solve()<<endl;
    T.erase(T.begin(),T.end());
  }
  return 0;
}

Measured memory_bytes: 3128
use std::collections::HashMap;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input!{
        n: usize,
        m: usize,
        py: [(u64, u64); m],
    }

    let mut map: HashMap<u64, Vec<(u64, usize)>> = HashMap::new();
    for (i, &(p, y)) in py.iter().enumerate() {
        map.entry(p).or_insert(Vec::new()).push((y, i));
    }

    // for (p, v) in &map {
    //     for &(y, i) in v {
    //         println!("{}, {}, {}", p, y, i);
    //     }
    // }

    let mut answer = Vec::new();
    for (p, v) in &mut map {
        // 県ごとに市をソート
        v.sort_by_key(|&(y, _)| y);

        for (x, &(_, i)) in v.iter().enumerate() {
            answer.push((i, format!("{:06}{:06}", p, x+1)))
        }
    }

    answer.sort_by_key(|&(i, _)| i);

    for &(_, ref answer) in &answer {
        println!("{}", answer);
    }
}


Measured memory_bytes: 25776
// problem: "https://atcoder.jp/contests/abc144/tasks/abc144_a"

#include<bits/stdc++.h>

using namespace std;

int main()
{
    int a,b;
    cin>>a>>b;

    if(a <= 9 && a >= 1 && b <= 9 && b >= 1)
        cout<<a*b;

    else
        cout<<-1;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define sz(x) int(x.size())

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

    int N = sz(S);

    string F = S.substr(0, (N - 1) / 2);
    string E = S.substr((N - 1) / 2 + 1);

    bool Sp = equal(S.begin(), S.begin() + N/2, S.rbegin());
    bool Fp = equal(F.begin(), F.begin() + N/2, F.rbegin());
    bool Ep = equal(E.begin(), E.begin() + N/2, E.rbegin());

    cout << (Sp && Fp && Ep ? "Yes\n" : "No\n");
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ull, ull> UP;
typedef tuple<int, int, int> T;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
ll digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
ll countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}


int main() {
	IOS;
	int n, m;
	cin >> n >> m;
	vector<int> cnt(n,0);
	int x;
	REP(i, 2 * m) {
		cin >> x;
		cnt[x - 1]++;
	}
	REP(i, n)cout << cnt[i] << endl;
}



Measured memory_bytes: 256
def sol():
    mod=1000000007
    ans=0
    n=int(input())
    a=[int(i) for i in input().split()]
    x=[[0]*61 for i in range(n+1)]
    l=[pow(2,i,mod) for i in range(61)]
 
    for i in range(n):
        d=a[i]
        cnt=0
        for j in range(61):
            if d&1:
                x[i+1][cnt]=x[i][cnt]+1
            else:
                x[i+1][cnt]=x[i][cnt]
            cnt+=1
            d=d>>1
 
    for i in range(1,n):
        for j in range(61):
            p=x[i][j]-x[i-1][j]
            if p:
                ans+=l[j]*((n-i)-(x[-1][j]-x[i][j]))
            else:
                ans+=l[j]*(x[-1][j]-x[i][j])
            ans%=mod
    print(ans)
 
if __name__=="__main__":
    sol()

Measured memory_bytes: 203084
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  cin >> N >> K;
  
  int dist = 0;
  for (int i=0;i<N;i++) {
    int x;
    cin >> x;
    if (x*x < (K-x)*(K-x)) {
      dist += 2*x;
    }
    else if (K-x >= 0){
      dist += 2*(K-x);
    }
    else {
      dist += 2*(x-K);
    }
  }
  cout << dist << endl;
}

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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
//#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

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> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
void vin(Vi &v){REP(i,0,(v).size()) cin>>v[i];}
void vin(Vi &v,Vi &v2){REP(i,0,(v).size()) cin>>v[i]>>v2[i];}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
int lesscount(int x,Vi &a){return lower_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx未満の数の個数
int orlesscount(int x,Vi &a){return upper_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx以下の数の個数
int morecount(int x,Vi &a){return a.size()-orlesscount(x,a);} //vector aにおけるxより大きい数の個数
int ormorecount(int x,Vi &a){return a.size()-lesscount(x,a);} //vector aにおけるx以上の数の個数
Vi accum(Vi v){Vi ret((v).size()+1);REP(i,0,(v).size()) ret[i+1]=ret[i]+v[i];return ret;}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}


void solve(long long n, long long m, std::vector<long long> a){
    sort(ALL(a));

    int low=0,high=INF;
    while(high-low>1){
        int x=(low+high)/2;
        int count=0;
        REP(i,0,n){
            count += ormorecount(x-a[i],a);
        }
        if(count<m) high=x;
        else low=x;
    }

    Vi wa=accum(a);
    int ans=0;

    REP(i,0,n){
        int mcount=ormorecount(high-a[i],a);
        ans += mcount*a[i] + (wa[n]-wa[n-mcount]);
        m -= mcount;
    }
    ans += m*low;
    cout<<ans<<endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
signed main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, M, std::move(A));
    return 0;
}


Measured memory_bytes: 2688
from heapq import heappush, heappop
from collections import deque
N, M = map(int, input().split())
S, T = map(int, input().split())
S -= 1; T -= 1
G = [[] for i in range(N)]
for i in range(M):
    u, v, d = map(int, input().split())
    G[u-1].append((v-1, d))
    G[v-1].append((u-1, d))

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

dist = [INF]*N
dist[S] = 0
que = [(0, S)]
while que:
    cost, v = heappop(que)
    if dist[v] < cost:
        continue
    for w, c in G[v]:
        if cost + c < dist[w]:
            dist[w] = cost + c
            heappush(que, (cost + c, w))

que = deque()
mi = [0]*N
que.append(T)
mi[T] = 1
H = [[] for i in range(N)]
RH = [[] for i in range(N)]

D = dist[T]

V = []
E = []
while que:
    v = que.popleft()
    d = dist[v]
    if d*2 == D:
        V.append(v)
    for w, c in G[v]:
        if d == dist[w] + c:
            if dist[w]*2 < D < d*2:
                E.append((w, v))
            H[v].append(w)
            RH[w].append(v)
            if mi[w] == 0:
                mi[w] = 1
                que.append(w)

def bfs(G, RG, s):
    *deg, = map(len, RG)
    que = deque([s])
    res = [0]*N
    res[s] = 1
    while que:
        v = que.popleft()
        for w in G[v]:
            deg[w] -= 1
            res[w] += res[v]
            if deg[w] == 0:
                que.append(w)
                res[w] %= MOD
    return res
CT = bfs(H, RH, T)
CS = bfs(RH, H, S)

ans = CS[T] * CT[S] % MOD
for v in V:
    ans -= (CS[v] * CT[v]) ** 2
    ans %= MOD
for v, w in E:
    ans -= (CS[v] * CT[w]) ** 2
    ans %= MOD
print(ans)


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

using namespace std;
typedef long long ll;
typedef long double lb;
#define mod 10000000007
#define REP(i,j,n) for (int i=j;i<(n);i++)
#define RREP(i,n) for (int i = n; 0<i;i--)
#define print(out) cout<< out  << "\n"

int main(){
  int N;cin>>N;
  int x_l[N];
  double P=0.0;
  REP(x,0,N){
    cin>>x_l[x];
    P+=x_l[x];
  }
  P=round(P/N);
  int ans=0;
  REP(i,0,N){
    ans+=pow((x_l[i]-P),2);
  }
  print(ans);

}

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


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int Sum = 0;
  int max = -1000000000;
  int num;
  if(a > max){
    max = a;
    num = 0;
  }
  if(b > max){
    max = b;
    num = 1;
  }
  if(c > max){
    max = c;
    num = 2;
  }
  if(num == 0){
    Sum = a * pow(2,d) + b + c;
  }
  if(num == 1){
    Sum = b * pow(2,d) + a + c;
  }
  if(num == 2){
    Sum = c * pow(2,d) + a + b;
  }
  cout << Sum << endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15); //"for float-base
  // problem"
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end(), greater<char>());
  if (s < t)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int a[2005];
 
int main()
{
  int N, A, B;
  scanf("%d%d%d", &N, &A, &B);
  for (int i = 0; i < N; ++i) {
    scanf("%d", a + i);
  }
  int ans = abs(a[N - 1] - B);
  if (N >= 2) ans = max(ans, abs(a[N - 1] - a[N - 2]));
  printf("%d\n", ans);
  return 0; 
}

Measured memory_bytes: 256
//  Mayank Agarwal
//  IIIT Hyderabad



#include<bits/stdc++.h>
using namespace std;
const long long int M = 1000000007; 
#define ll long long int
#define ld double
#define pb push_back
#define mp make_pair
ll power(ll x, ll y,  ll p) 
{ 
    ll res = 1;      
    x = x % p;   
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1;x = (x*x) % p; 
    } return res%p; 
} 
ll modinver(ll a,ll b)
{
    return (power(a,1,M)*power(b,M-2,M))%M;
}
void SieveOfEratosthenes(int n) 
{   
    bool prime[10005]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
} 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n;
    cin>>n;
    ll a[200],v[1000];
    ll ans=0;
    for (int i = 0; i < n; ++i)
    {
    	cin>>a[i];
    }
    for (int i = 0; i < n; ++i)
    {
    	ll b;
    	cin>>b;
    	if(a[i]>b)
    	{
    		ans+=a[i]-b;
    	}    
    }
    cout<<ans<<'\n';
}


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

int main() {
    int A; cin >> A;
    char op; cin >> op;
    int B; cin >> B;
    if (op == '+') {
        cout << A + B << endl;
    }
    else {
        cout << A - B << endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int N,H[500],i,j;
long long R=1;
int cmp(const int *a,const int *b){return *b-*a;}
int main()
{
	scanf("%d",&N);
	for(i=0;i<N;i++)scanf("%d",&H[i]);
	qsort(H,N,4,cmp);
	for(i=0;i<N;i++)
		R+=(H[i]-i/4)>0?(H[i]-i/4):0;
	printf("%lld\n",R);
	return 0;
}

Measured memory_bytes: 644
import sys

def input():
    return sys.stdin.readline().rstrip()

if __name__ == "__main__":
    n = int(input())
    l = [1] + [6**i for i in range(1, 8) if 6**i <= n] + [9**i for i in range(1, 7) if 9**i <= n]
    l.sort()

    inf = float("inf")
    dp = [inf for i in range(n+1)]
    dp[0] = 0

    for i in range(n):
        for e in l:
            if i + e <= n:
                dp[i+e] = min(dp[i] + 1, dp[i+e])
            else:
                break

    print(dp[n])


Measured memory_bytes: 3864
#include<iostream>
#include<string.h>
using namespace std;

int numofbits(int 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 main() {
  int n,s,dp[1024][400];
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;
  for(int i=0; i<1024; ++i)
    for(int j=0; j<400; ++j)
      if(dp[i][j] != 0) {
	int t = numofbits(i)+1;
	for(int k=0; k<10; ++k)
	  if(!(1<<k & i)) {
	    if(j+t*k >= 400) break;
	    dp[i|1<<k][j+t*k] += dp[i][j];
	  }
      }

  while(cin>>n>>s) {
    int ans = 0;
    for(int i=0; s<400 && i<1024; ++i)
      if(numofbits(i) == n) ans += dp[i][s];
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 0
s = gets.chomp
t = gets.chomp
min = t.length
0.upto (s.length - t.length){ |i|
	cnt = 0
	t.length.times{ |j|
		if(s[i+j] != t[j]) then
			cnt += 1
		end
	}
	if(min > cnt) then
		min = cnt
	end
}
p min

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

int main()
{
   int k;string s;
   cin>>k>>s;
   if(s.length()>k)
   {
   for(int i=0;i<k;i++) cout<<s[i];
   cout<<"..."<<"\n";
   }
   else cout<<s<<"\n";
}

Measured memory_bytes: 3624
#include<stdio.h>

int main(){
    int n;
    scanf("%d",&n);
    int array[n];
    for(int i = 0;i < n;i++)    scanf("%d",&array[i]);
    for(int i = n;i > 0;i--){
        if(i != 1){
            printf("%d ",array[i-1]);
        } else{
            printf("%d\n",array[i-1]);
        }
    }
}



Measured memory_bytes: 2744
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
#include<iostream>
using namespace std;
int main(){
int N,K,X,Y;
cin >>N>>K>>X>>Y;

if(N<=K) cout<<N*X<<endl;
else cout<<K*X+(N-K)*Y<<endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    int count=0;

    for (int i=0;i<n;i++){
        int min_idx=i;
        for(int j=i; j<n; j++){
            if(a[min_idx]>a[j]) {
                min_idx=j;
            }
        }
        if(min_idx != i) {
            swap(a[i], a[min_idx]);
            count += 1;
        }
    }


    for(int k = 0;k<n-1;k++)
        cout<<a[k]<<' ';
    cout<<a[n-1];
    cout<<endl;
    cout<<count<<endl;

    return 0;
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  int l[n];
  int sum=0;
  
  for(int i=0;i<n;i++){
    cin>>l[i];
  }
  sort(l,l+n,greater<int>());//大きい順にsort
  for(int j=0;j<k;j++){
    //cout<<sum<<" ";
    sum=sum+l[j];
  }

	cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<ll,pll> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n;
vp a;
set<int> st;
ll res=0;

//a,b,c,d,e
//res+=(b-a)*(d-c)+(c-b)*(e-d);

int main(){
	cin>>n;
	a=vp(n);
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		a[i]={x,i};
	}
	sort(a.rbegin(),a.rend());
	st.insert(-1);
	st.insert(n);
	for(int i=0;i<n;i++){
		ll x=a[i].first,id=a[i].second,L2,L1,R1,R2;
		auto it=st.insert(id).first;
		it--;
		if(*it==-1) L1=L2=-1;
		else{
			L1=*it;
			it--;
			L2=*it;
			it++;
		}
		it++;it++;
		if(*it==n) R1=R2=n;
		else{
			R1=*it;
			it++;
			R2=*it;
			it--;
		}
		res+=x*((L1-L2)*(R1-id)+(id-L1)*(R2-R1));
	}
	cout<<res<<endl;
}

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

const int MAX = 100000;
int main() {
  	ios::sync_with_stdio(false);
  	cin.tie(0);
	int N, A[MAX];
	cin >> N;
	for (int i = 0;i < N;++ i) cin >> A[i];
	sort(A, A+N);
	
	int64_t ans1 = A[N >> 1] - A[0], ans2 = A[N - 1] - A[N >> 1];
	for (int i = 1;i < N - 1;++ i) {
		ans1 += abs(A[i >> 1] - A[N - (i + 1 >> 1)]);
		ans2 += abs(A[i - 1 >> 1] - A[N - (i + 2 >> 1)]);
	}
	cout << max(ans1, ans2);
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

ごめんなさい、ちょっと黒魔術試してみたくなっただけ
*/


Measured memory_bytes: 640
def main():
    N,M,Q = map(int, input().split())

    
    X = [[0 for _ in range(N)] for _ in range(N)]
    """
    for i in range(M):
        l,r = map(int, input().split())
        X[l-1][r-1] += 1
    """

    LR = [list(map(int, input().split())) for _ in range(M)]
    query = [tuple(map(int, input().split())) for _ in range(Q)]

    for l,r in LR:
        X[l-1][r-1] += 1

    """
    C[i][j]：iから出発してjまで（ｊを含む）のどこかに行くもの
    C[i][j] = X[i][i] + X[i][i+1] + ... + X[i][j-1] + X[i][j]
    """
    C =  [[0 for _ in range(N)] for _ in range(N)]
    for i in range(N):
        for j in range(N):
            C[i][j] = C[i][j-1] + X[i][j]


    """
    print("---------------")
    for a in C:
        print(a)
    """

    for p,q in query:
        cnt = 0
        for r in range(p-1,q):
            cnt += C[r][q-1]
        print(cnt)


if __name__ == "__main__":
    main()

Measured memory_bytes: 109528
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

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

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

//-----------------------ここから-----------


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

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

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

	sort(tmp.begin(), tmp.end());

	int center = n / 2;

	int medi1 = tmp[center];
	int medi2 = tmp[center - 1];

	for(int i = 0; i < n; i++){
		if(x[i] < medi2){
			cout << medi1 << endl;
		} else if(x[i] > medi2){
			cout << medi2 << endl;
		} else {
			cout << medi1 << endl;
		}
	}	
}



Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define pq priority_queue
using namespace std; typedef pair<int, int> P; typedef pair<int, P> P2; typedef pair<int, P2> P3;
constexpr long long gcd(long long a, long long b){return b ? gcd(b, a % b) : a;}
constexpr long long lcm(long long a, long long b){return a / gcd(a, b) * b;}
constexpr int INF = 1e9, MOD = INF + 7, around[] = {0, 1, 1, -1, -1, 0, -1, 1, 0, 0};
constexpr int mod_pow(long long x, long long n, const int mod){long long ret=1;while(n){if(n&1)(ret*=x)%=mod;(x*=x)%=mod;n>>=1;}return ret;}
template<int n> struct Prime{bool arr[n+1];constexpr bool operator[](int k){return arr[k];}constexpr Prime():arr(){for(int i=2;i<n;i++){arr[i]=true;for(int j=2;j*j<=i;j++){if(!(i%j))arr[i]=false;}}}};
template<int n> struct Factorial{long long arr[n+1],ary[n+1];constexpr Factorial():arr(),ary(){arr[0]=1;ary[0]=1;for(int i=0;i<n;i++){arr[i+1]=arr[i]*(i+1)%MOD;ary[i+1]=mod_pow(arr[i+1],MOD-2,MOD);}}};
constexpr Factorial<1010> fact; constexpr Prime<10> prime;
constexpr long long comb(int a, int b){if(a < b) return 0LL;if(!a or !b) return 1LL; long long pos = fact.arr[a], pot = fact.ary[a - b], por = fact.ary[b]; return pos * pot % MOD * por % MOD;}
template<int n> struct Bernoulli{long long arr[n+1];constexpr Bernoulli():arr(){arr[0]=1;for(int i=1;i<=n;i++){long long sum=0;for(int j=0;j<i;j++){(sum+=comb(i+1,j)*arr[j]%MOD)%=MOD;}arr[i]=(MOD-mod_pow(i+1,MOD-2,MOD))%MOD*sum%MOD;}}};
constexpr int vx[] = {1, 0, -1, 0}, vy[] = {0, 1, 0, -1};
constexpr long double PI = abs(acos(-1));
constexpr int sqrtN = 512, logN = 32;
constexpr long long LINF=1e18;

int main(){
	string s; cin >> s;
	
	string w = s, mi = "-1";
	while(true){
		for(char j = 'a'; j <= 'z'; j++){
			string t = w + j;
			
			bool used[30] = {}, f = false;
			for(int k = 0; k < t.size(); k++){
				if(used[t[k] - 'a']){
					f = true;
					break;
				}
				
				used[t[k] - 'a'] = true;
			}
			
			if(f) continue;
			if(t <= s) continue;
			if(mi == "-1") mi = t;
			mi = min(mi, t);
		}
		
		if(w.size() == 0) break;
		w.pop_back();
	}
	
	cout << mi << endl;
	return 0;
}


Measured memory_bytes: 256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1.0);

const int mod = (int) 1e9 + 7;

void add(int &x, int y) {
  if ((x += y) >= mod) {
    x -= mod;
  }
}

int mult(int x, int y) {
  return (long long) x * y % mod;
}

int myPower(int x, int pw) {
  int res = 1;
  for (; pw; pw >>= 1) {
    if (pw & 1) {
      res = mult(res, x);
    }
    x = mult(x, x);
  }
  return res;
}

void precalc() {
}


const int maxn = (int) 2e5 + 10;
int a[maxn];

int n, m;

int read() {
  if (scanf("%d", &n) < 1) {
    return 0;
  }
  m = 2 * n - 1;
  for (int i = 0; i < m; ++i) {
    scanf("%d", a + i);
  }
  return 1;
}

int b[maxn];

int get() {
  pair<int, int> best(inf, -1);
  for (int i = 0; i < m;) {
    int i0 = i;
    while (i < m && b[i] == b[i0]) {
      ++i;
    }
    if (i - i0 == 1) {
      continue;
    }
    int cur = (i0 <= n - 1 && n - 1 < i) ? 0 : min(abs(i - 1 - (n - 1)), abs(i0 - (n - 1)));
    best = min(best, mp(cur, b[i0]));
  }
  if (best.second != -1) {
    return best.second;
  }
  return b[0];
}

void solve() {
  int left = 1, right = 2 * n - 1;
  while (left + 1 < right) {
    int mid = (left + right) / 2;
    for (int i = 0; i < m; ++i) {
      b[i] = (a[i] > mid);
    }
    if (get()) {
      left = mid;
    } else {
      right = mid;
    }
  }
  printf("%d\n", right);
}

int main() {
  precalc();
#ifdef LOCAL
  freopen(TASK ".out", "w", stdout);
  assert(freopen(TASK ".in", "r", stdin));
#endif

  while (1) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;
const int INF = 1e9;

// dp[i][t] := i?????????????????§?????????????????????????¨?t???????????¨????????????????????????????¨?
int dp[2][1010];
int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  while(cin>>N,N){
	vector<PII> xs(N);
	REP(i,N) cin >> xs[i].FF >> xs[i].SS;
	SORT(xs);

	int mx = xs.back().FF;
	int sum = accumulate(ALL(xs), 0,
						 [](int s, PII x){ return s+x.FF;}) - mx;
	if(sum >= mx){
	  cout << accumulate(ALL(xs), sum+mx,
						 [](int s, PII x){ return s+x.SS;}) << endl;
	}
	else{
	  int crt = 0, nxt = 1;
	  fill(dp[crt], dp[crt]+1010, -INF);
	  dp[crt][0] = 0;
	  REP(i,N-1){
		fill(dp[nxt], dp[nxt]+1010, -INF);
		REP(t,mx+1){
		  int nxt_t = t + xs[i].FF;
		  if(nxt_t <= mx){
			dp[nxt][nxt_t] = max(dp[nxt][nxt_t], dp[crt][t]);
			nxt_t += xs[i].SS;
			if(nxt_t <= mx)
			  dp[nxt][nxt_t] = max(dp[nxt][nxt_t], dp[crt][t] + xs[i].SS);
		  }
		}
		swap(crt, nxt);
	  }
	  int tmp = 0;
	  REP(t,mx+1) tmp = max(tmp, dp[crt][t]);
	  int ans = accumulate(ALL(xs), -tmp, [](int s, PII x){return s+x.SS;});
	  cout << ans + 2*mx << endl;
	}
  }
  
  return 0;
}

Measured memory_bytes: 3188
#include<stdio.h>
int main(void){
    int a,b;
    while(scanf("%d %d",&a,&b)!=EOF){
        int add_ab=a+b;
        int digit=0;
        while(add_ab!=0){
            add_ab/=10;
            ++digit;
        }
        printf("%d\n",digit);
    }
    return 0;
}


Measured memory_bytes: 2012
#include <iostream>
#include <vector>
#include <map>

using namespace std;

struct Nat : public map<int, int>
{
  Nat(int x = 1)
  {
    if (x == 1)
      return;
    int k = 0;
    while (!(x & 1)) {
      x >>= 1;
      ++k;
    }
    if (k > 0)
      operator[](2) = k;
    for (int i = 3; i * i <= x; i += 2) {
      int k = 0;
      while (x % i == 0) {
	x /= i;
	++k;
      }
      if (k > 0)
	operator[](i) = k;
    }
    if (x > 1)
      operator[](x) = 1;
  }
  
  Nat operator*(const Nat& y) const
  {
    if (empty()) return y;
    if (y.empty()) return *this;
    
    Nat z;
    auto i = begin();
    auto j = y.begin();
    while (i != end() || j != y.end()) {
      if (i == end()) {
	z[j->first] = j->second;
	++j;
	continue;
      }
      if (j == y.end()) {
	z[i->first] = i->second;
	++i;
	continue;
      }
      if (i->first < j->first) {
	z[i->first] = i->second;
	++i;
	continue;
      }
      if (i->first > j->first) {
	z[j->first] = j->second;
	++j;
	continue;
      }
      z[i->first] = i->second + j->second;
      ++i;
      ++j;
    }
    return z;
  }

  operator int() const {
    int z = 1;
    for (auto i : *this) {
      for (int j = 0; j < i.second; ++j)
	z *= i.first;
    }
    return z;
  }
  
  static vector<int> P;
};

const int MOD = 1000000000 + 7;

int countDivisor(const Nat& n)
{
  long long c = 1;
  for (auto i : n) {
    c = c * (i.second + 1) % MOD;
  }
  return c;
}

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

  Nat f;
  
  for (int i = 2; i <= N; ++i) {
    f = f * Nat(i);
  }
  cout << countDivisor(f) << "\n";
  
  return 0;
}


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

int main() {
    int N, M; cin >> N >> M;
    priority_queue<int> prices;
    for(int i=0; i < N; i++){
        int A; cin >> A;
        prices.push(A);
    }
    for(int i=0; i < M; i++) {
        prices.push(prices.top() / 2);
        prices.pop();
    }
    long long ans = 0;
    for(int i=0; i < N; i++) {
        ans += prices.top();
        prices.pop();
    }
    cout << ans << endl;
}

Measured memory_bytes: 892
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 1
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif


//改造
typedef long long int ll;
using namespace std;


//ここから編集する

int main() {
    vector<int> v;
    int tmp;
    for(int i = 0; i < 3; i++){
        cin >> tmp;
        v.push_back(tmp);

    }

    sort(v.begin(),v.end());
    int go[] = {5,5,7};
    for(int i = 0; i < 3; i++){
        if(go[i] != v[i]){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;

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

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

	int len = s.length();

	for (int i = 0;i < len;i++) {
		if (s[i] != s[len - 1 - i]) {
			cout << "No" << endl;
			return 0;
		}
	}


	cout << "Yes" << endl;
	return 0;
}

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

struct Benri {
    Benri() {
        std::cin.tie(0); ios::sync_with_stdio(false);
        cout << fixed << setprecision(12);
    }
} benri;
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; }

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define MOD 1000000007LL
#define MOD2 998244353LL
const int INF = 1 << 28;



vector< int > z_algorithm(const string &s) {
    vector< int > prefix(s.size());
    for (int i = 1, j = 0; i < s.size(); i++) {
        if (i + prefix[i - j] < j + prefix[j]) {
            prefix[i] = prefix[i - j];
        } else {
            int k = max(0, j + prefix[j] - i);
            while (i + k < s.size() && s[k] == s[i + k]) ++k;
            prefix[i] = k;
            j = i;
        }
    }
    prefix[0] = (int) s.size();
    return prefix;
}


const int maxv = 500005;
vi Grh[maxv];
vi indeg(maxv);
vi path(maxv);
vi color(maxv);



//cycle検出のみ
bool dfs1(int v) {
    if (color[v] == 0) color[v]  = 1;
    bool f = true;

    for (auto next : Grh[v]) {
        if (color[next] == 2) continue;
        if (color[next] == 1) return false;
        f &= dfs1(next);
    }

    color[v] = 2;
    return f;
}

//DAGのパス長
int dfs2(int v) {
    int &res = path[v];
    if (~res) return res;
    res = 0;

    for (auto next : Grh[v]) {
        res = max (res, dfs2(next) + 1);
    }
    return res;
}



int main() {
    string s, t; cin >> s >> t;
    int n = s.size(), m = t.size();
    string u = s;
    while (u.size() < n + m) {
        u += s;
    }
    string v = t + "*" + u;
    vi Z = z_algorithm(v);

    rep(i, n) {
        if (Z[m + 1 + i] == m) {
            Grh[i].pb((i + m) % n);
            indeg[(i + m) % n]++;
        }
    }


    color.assign(n, 0);
    bool fin = true;


    //cycle 検出
    rep(i, n) {
        if (color[i] == 2) continue;
        if (!dfs1(i)) {
            fin = false;
            break;
        }
    }

    if (!fin) {
        cout << -1 << endl;
    }
    else {
        int ans = -1;
        path.assign(n, -1);

        rep(i, n) {
            if (indeg[i] != 0) continue;
            int tmp = dfs2(i);
            chmax(ans, tmp);
        }

        cout << (fin ? ans : -1) << endl;

    }

}




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

int main(){
  int x,a;
  cin >> x >> a;
  if(x < a) cout << 0;
  else cout << 10;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100001
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
// clang-format on

int N;
int d[MAX_N];

int main(void)
{
  scanf("%d", &N);
  REP(i, N) scanf("%d", &d[i]);
  sort(d, d + N);
  int cnt = 0;
  for (int i = 0; i < MAX_N; i++) {
    int k = lower_bound(d, d + N, i) - d;
    if (k == (N - k)) cnt++;
  }
  printf("%d\n", cnt);
  return 0;
}


Measured memory_bytes: 888
from collections import defaultdict

def prime_factorization(n):
    '''
    Trial division.
    Input: 
        n : a positive integer
    Output:
        a dictionary of #(each prime factors) of n,
    '''
    result = defaultdict(int)
    if n < 2:
        return result
    while n % 2 == 0:
        result[2] += 1
        n //= 2
    p = 3
    while p*p <= n:
        while n % p == 0:
            n //= p
            result[p] += 1
        p += 2
    if n > 1:
        result[n] += 1
    return result

N = int(input())
ans = 0
if N >= 2:
    p = 1
    while p*p <= N:
        q, r = divmod(N, p)
        if r == 0 and p < q - 1:
            ans += q - 1
        p += 1
print(ans)

Measured memory_bytes: 3316
n,k = map(int,input().split())
x = list(map(int,input().split()))
tmp = []
for i in range(n-k+1):
    tmp.append(abs(x[i])+abs(x[i+k-1]-x[i]))
x_2 = x
x_2.reverse()

for j in range(n-k+1):
    tmp.append(abs(x_2[j])+abs(x_2[j+k-1]-x_2[j]))
print(min(tmp))


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

int n;
int a[20] = {400, 800, 1200, 1600, 2000, 2400, 2800, 3200, 10000000};
int d[10];
int u;
int col(int nd)
{
	int i = 0;
	while (a[i] <= nd) i++;
	// cout << i << endl;
	return i;
}

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%d", &u), d[col(u)]++;
	int cnt = 0;
	for (int i = 0; i < 8; i++)
		cnt += (d[i] != 0);
	if (cnt == 0) {
		cout << 1 << " " << d[8] << endl;
	} else {
		cout << cnt << " " << cnt+d[8] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#map(int, input().split())
from collections import deque
N, M = map(int, input().split())
graph = {i:deque() for i in range(1, N+1)}

for _ in range(M):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

seen = [0]*(N+1)
queue = deque()
dist = [-1]*(N+1)
dicgq = {i: 0 for i in range(2, N+1)}
dicqg = {i: 0 for i in range(2, N+1)}

def bfs(v):
    dist[v] = 0
    seen[v] = 1
    queue.append(v)
    while queue:
        q = queue[0]
        if not graph[q]:
            queue.popleft()
            continue
        g = graph[q].popleft()
        if seen[g]:
            continue
        seen[g] = 1
        dist[g] = dist[q] + 1
        dicgq[g] = q # mitisirube
        dicqg[q] = g # graph
        queue.append(g)

bfs(1)
pre_dis = dist.copy()

for i in range(2, N+1):
    graph[i] = dicqg[i]



seen = [0]*(N+1)
queue = deque()
def bfs2(v):
    dist[v] = 0
    seen[v] = 1
    queue.append(v)
    while queue:
        q = queue[0]
        if not graph[q]:
            queue.popleft()
            continue
        g = graph[q].popleft()
        if seen[g]:
            continue
        seen[g] = 1
        dist[g] = dist[q] + 1
        
        queue.append(g)


bfs2(1)
if pre_dis != dist:
    print("No")
else:
    print("Yes")
    for i in range(2, N+1):
        print(dicgq[i])

Measured memory_bytes: 170668
<?php
$C=str_split(fgets(STDIN));
foreach($C as $c){
	$n=ord($c);
	if(64<$n && $n<91) $c=chr($n+32);
	elseif(96<$n && $n<123) $c=chr($n-32);
	echo $c;
}
/*
$S=fgets(STDIN);
$l=strlen($S);
for($i=0;$i<$l;$i++){
	$n=ord($S[$i]);
	if(64<$n && $n<91) print chr($n+32);
	elseif(96<$n && $n<123) print chr($n-32);
	else print $S[$i];
}
*/

Measured memory_bytes: 15196
N = int(input())
list1 = [int(input()) for i in range(N)]

max1 = list1.index(max(list1))
max2 = max(list1)
list2 = list1[:max1]+list1[max1+1:]
max3 = max(list2)

for i in range(N):
  if i != max1:
    print(max2)
  else:
    print(max3)



Measured memory_bytes: 14124
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll x, ll y) {
	ll res = 1;
	for (ll i = 0; i < y; i++) res = res * x % mod;
	return res;
}

int main() {
	ll x;
	cin >> x;
	ll ans = 0;
	ll money = 100;
	while (money < x) {
		ans++;
		money = money + money / 100;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3572
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <array>
using namespace std;

typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<n+1;i++)
int main(){
    int l;
    string S;
    cin>>S;
    l=S.size();
    ll dp[100001][3][4];
    rep(i,3)rep(j,4) dp[0][i][j]=0;
    int num=0;
    Rep(i,l){
        if(S[i-1]=='A'){
            rep(j,3)rep(k,4)dp[i][j][k]=dp[i-1][j][k];
            dp[i][0][0]++;
            rep(j,3)rep(k,4) dp[i][j][k]=dp[i][j][k]%mod;
        }else if(S[i-1]=='B'){
            rep(j,3)rep(k,4)dp[i][j][k]=dp[i-1][j][k];
            dp[i][1][0]+=dp[i-1][0][0];
            dp[i][1][1]+=dp[i-1][0][1];
            rep(j,3)rep(k,4) dp[i][j][k]=dp[i][j][k]%mod;
        }else if(S[i-1]=='C'){
            rep(j,3)rep(k,4)dp[i][j][k]=dp[i-1][j][k];
            dp[i][2][0]+=dp[i-1][1][0];
            dp[i][2][1]+=dp[i-1][1][1];
            dp[i][2][2]+=dp[i-1][1][2];
            rep(j,3)rep(k,4) dp[i][j][k]=dp[i][j][k]%mod;
        }else{
            rep(j,3)rep(k,4)dp[i][j][k]=dp[i-1][j][k];
            dp[i][0][1]+=1;
            dp[i][1][1]+=dp[i-1][0][0];
            dp[i][1][2]+=dp[i-1][0][1];
            dp[i][2][1]+=dp[i-1][1][0];
            dp[i][2][2]+=dp[i-1][1][1];
            dp[i][2][3]+=dp[i-1][1][2];
            rep(j,3)rep(k,4) dp[i][j][k]=dp[i][j][k]%mod;
            num++;
        }
    }
    ll ans;
    if(num==0) cout<<dp[l][2][0]<<endl;
    else if(num==1) cout<<(dp[l][2][0]*3+dp[l][2][1])%mod<<endl;
    else if(num==2) cout<<(dp[l][2][0]*9+dp[l][2][1]*3+dp[l][2][2])%mod<<endl;
    else{
        ans=(dp[l][2][0]*27+dp[l][2][1]*9+dp[l][2][2]*3+dp[l][2][3])%mod;
        rep(i,num-3){
            ans=(ans*3)%mod;
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 9856
//y15-4
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define segment_size 65536
#define ROOP() while (true)

int main(){
    bool A[100],B[100],C[100];
    int N,X,Y,Z;
    cin >> N;
    for(int i=0; i<N; i++){
        A[i] = false;
        B[i] = false;
        C[i] = false;
    }
    cin >> X;
    for(int i=0; i<X; i++){
        int tmp;
        cin >> tmp;
        tmp--;
        A[tmp] = true;
    }
    cin >> Y;
    for(int i=0; i<Y; i++){
        int tmp;
        cin >> tmp;
        tmp--;
        B[tmp] = true;
    }
    cin >> Z;
    for(int i=0; i<Z; i++){
        int tmp;
        cin >> tmp;
        tmp--;
        C[tmp] = true;
    }

    set<int> ans;
    for(int i=0; i<N; i++){
        if(A[i]==false && C[i]==true) ans.insert(i);
        if(B[i]==true && C[i]==true) ans.insert(i);
    }
    cout << ans.size() << endl;

    return 0;
}



Measured memory_bytes: 3100
import sys
from heapq import heappush, heappop
input = sys.stdin.readline
data = []
n,q = map(int,input().split())
for i in range(n):
    s, t, x = map(int, input().split())
    data.append([s-x,t-x,x])
data.sort(key=lambda x:x[0])
d_index = 0
candidate_x = []
inf = float("inf")
data += [[inf,inf,inf]]
for i in range(q):
    d = int(input())
    while d >= data[d_index][0]:
        heappush(candidate_x, (data[d_index][2], data[d_index][1]))
        d_index += 1
    if len(candidate_x) == 0:
        print(-1)
    else:
        while candidate_x:
            x,finish_t = heappop(candidate_x)
            if finish_t > d:
                heappush(candidate_x, (x, finish_t))
                print(x)
                break
        else:
            print(-1)





Measured memory_bytes: 122716