akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
#define N 1000000
using namespace std;

int main(){
	int n,k;
	scanf(" %d %d", &n , &k);
	int *a = new int[N];
	for(int i=0;i<n;i++){
		scanf(" %d", &a[i]);
	}
	
	int low=0,high=1e9,mid;
	for(int _=0;_<100;_++){
		mid = (low+high)/2;
		int count=0, bef=0;
		bool f = true;
		while(1){
			if(bef == n) break;
			if(count >= k){
				f = false;
				break;
			}
			int bag = mid;
			int p;
			for(p=bef;p<n;p++){
				if(bag >= a[p]) bag-=a[p];
				else break;
			}
			bef = p;
			count++;
		}
		if(f) high = mid;
		else low = mid;
	}
	
	printf("%d\n", high);	
	delete [] a;
	return 0;
}

Measured memory_bytes: 1528
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7

mb=format(max(a),'b')
arr=[0]*len(mb)

for i in range(n):
    b=format(a[i],'b')
    for j in range(len(b)):
        if b[-j-1]=='1':
            arr[j]+=1

ans=0

for i in range(len(mb)):
    ans+=arr[i]*(n-arr[i])*(2**i)
print(ans%mod)

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long  ll; typedef vector<int> VI; typedef pair<int,int> pii; typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);}


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VL a(n);
	rep(i, n) cin >>a[i];
	sort(a.rbegin(), a.rend());
	ll ans =0, ct =0;
	rep(i, n){
		if(i==0){ans += a[i]; ct++; continue;}
		if(ct >= n-1) break;
		ans += a[i]; ct++;
		if(ct >= n-1) break;
		ans += a[i]; ct++;
		
	}
	cout <<ans <<"\n";
	return 0;
}


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

int main(){
  int N,x;
  cin>>N>>x;
  
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin>>a.at(i);
  }
  sort(a.begin(),a.end());
  
  int ans = 0;
  for(int i=0;i<N-1;i++){
    if(a.at(i) <= x){
      ans++;
      x -= a.at(i);
    }else{
      cout<<ans <<endl;
      return 0;
    }
  }
  if(x==a.at(N-1)){
    ans++;
  }
  
  
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

const ll MOD = 1e9 + 7;
int n, m;
int x[100010], y[100010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> y[i];
  }
  ll a = 0, b = 0;
  for (int i = 0; i < n; i++) {
    a += (ll)(2 * i - n + 1) * x[i] % MOD;
    a %= MOD;
  }
  for (int i = 0; i < m; i++) {
    b += (ll)(2 * i - m + 1) * y[i] % MOD;
    b %= MOD;
  }
  cout << a * b % MOD << endl;

  return 0;
}

Measured memory_bytes: 1024
// #include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
 
// using namespace std;
using std::inplace_merge;
 
typedef long long ll;
 
typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
 
int n;
ll k;
ll a[252521];
ll tmp[252521];
 
ll solve(int l,int r){
  if(r-l==1){
    return 0ll;
  }
  int mid = (l+r)/2;
  ll ret = solve(l,mid) + solve(mid,r);
  int hl = l, hr = mid;
  FOR(i,l,r){
    if(hl<mid && (hr==r || a[hl]<=a[hr])){
      hl++;
    }else{
      ret += hl-l;
      hr++;
    }
  }
  inplace_merge(a+l,a+mid,a+r);
  return ret;
}
 
int main(){
  scanf("%d%lld",&n,&k);
  REP(i,n){
    scanf("%lld",a+i+1);
    a[i+1] += a[i] - k;
  }
  n++;
  ll ans = solve(0,n);
  printf("%lld\n",ans);
  return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}


const int INF=1001001001001001001ll;
int U[2222],V[2222],D[2222],C[2222];

vint dijkstra(vector<vpint>&G,int S){
    vint dist(G.size(),INF);
    dist[S]=0;
    priority_queue<pint,vector<pint>,greater<pint>>que;
    que.push({0,S});
    while(que.size()){
        int c,v;
        tie(c,v)=que.top();
        que.pop();
        if(dist[v]<c)continue;
        for(auto &e:G[v]){
            if(dist[e.fi]<=c+e.se)continue;
            dist[e.fi]=c+e.se;
            que.push({dist[e.fi],e.fi});
        }
    }
    return dist;
}


struct Dinic{
    struct edge{
        int to,cap,rev;
        edge(int to,int cap,int rev):to(to),cap(cap),rev(rev){}
    };

    const int INF=1001001001;
    vector<vector<edge>>G;
    vector<int>level,iter;
    Dinic(int v):G(v),level(v),iter(v){}

    void addEdge(int from,int to,int cap){
        G[from].push_back(edge(to,cap,G[to].size()));
        G[to].push_back(edge(from,0,G[from].size()-1));
    }

    void bfs(int s){
        fill(level.begin(),level.end(),-1);
        queue<int>que;
        level[s]=0;
        que.push(s);
        while(que.size()){
            int v=que.front();
            que.pop();
            for(auto &e:G[v]){
                if(e.cap&&level[e.to]==-1){
                    level[e.to]=level[v]+1;
                    que.push(e.to);
                }
            }
        }
    }

    int dfs(int v,int t,int f){
        if(v==t)return f;
        for(int &i=iter[v];i<G[v].size();i++){
            edge &e=G[v][i];
            if(e.cap>0&&level[v]<level[e.to]){
                int d=dfs(e.to,t,min(f,e.cap));
                if(d>0){
                    e.cap-=d;
                    G[e.to][e.rev].cap+=d;
                    return d;
                }
            }
        }
        return 0;
    }

    int maxFlow(int s,int t){
        int flow=0;
        while(true){
            bfs(s);
            if(level[t]<0)return flow;
            fill(iter.begin(),iter.end(),0);
            int f;
            while((f=dfs(s,t,INF))>0)flow+=f;
        }
    }
};


signed main(){
    int N,M,S,T;
    cin>>N>>M>>S>>T;
    S--;T--;

    vector<vpint>G(N);
    vector<vpint>rG(N);

    rep(i,M){
        cin>>U[i]>>V[i]>>D[i]>>C[i];
        U[i]--;V[i]--;
        G[U[i]].pb({V[i],D[i]});
        rG[V[i]].pb({U[i],D[i]});
    }

    vint distS=dijkstra(G,S);
    vint distT=dijkstra(rG,T);

    Dinic d(N);
    rep(i,M){
        if(distS[U[i]]+D[i]+distT[V[i]]!=distS[T])continue;
        d.addEdge(U[i],V[i],C[i]);
    }
    cout<<d.maxFlow(S,T)<<endl;
    return 0;
}



Measured memory_bytes: 3296
import java.util.*;

// Tenakaichi 2017-D
// http://tenka1-2017.contest.atcoder.jp/tasks/tenka1_2017_d	

public class Main {

	public static void main (String[] args) throws InterruptedException {
		Scanner in = new Scanner(System.in);

		int N = in.nextInt();
		int K = in.nextInt();

		ArrayList<int[]> pattern = new ArrayList<int[]>();
		int[] binary = convertToBinary(K);
		for (int i = 0; i < 32; i++) {
			if (binary[i] == 1) {
				binary[i] = 2;
			}
		}
		pattern.add(binary);
		fillPattern(pattern, K);
		
		int[] nums = new int[N];
		int[] values = new int[N];
		
		for (int i = 0; i < N; i++) {
			nums[i] = in.nextInt();
			values[i] = in.nextInt();
		}
		
		long answer = 0;
		for (int i = 0; i < pattern.size(); i++) {
			long tempAnswer = 0;
//			System.out.printf("pattern: ");
//			printBinary(pattern.get(i));
			for (int j = 0; j < N; j++) {
				if (doesMatchPattern(pattern.get(i), nums[j])) {
					tempAnswer += values[j];
				}
//				System.out.printf("num: %d, doesMatch: %s\n", nums[j], doesMatchPattern(pattern.get(i), nums[j]) ? "true" : "false");
			}
			answer = Math.max(answer, tempAnswer);
		}
		System.out.println(answer);
	}
	
	public static boolean doesMatchPattern(int[] pattern, int a) {
		for (int i = 0; i < 32; i++) {
			if (pattern[i] < 2) {
				if (((1 << i) & a) > 0 && pattern[i] == 0) {
					return false;
				}
				if (((1 << i) & a) == 0 && pattern[i] == 1) {
					return false;
				}
			}
		}
		return true;
	}
	
	public static void fillPattern(ArrayList<int[]> pattern, int a) {
		if (a > 0) {
			int index = 0;
			for (int i = 0; i <= 31; i++) {
				if (((1 << i) & a) > 0) {
					index = i;
					break;
				}
			}
			int[] binary = new int[32];
			binary[index] = 0;
			// Fill the right side of binary
			for (int i = 0; i < index; i++) {
				binary[i] = 2; // The bit containing 2 can be 1 or 0
			}
			
			// Fill the left side of binary
			for (int i = index + 1; i < 32; i++) {
				if (((1 << i) & a) > 0) {
					binary[i] = 2;
				}
			}
			
			pattern.add(binary);
			fillPattern(pattern, a - (1 << index));
		}
	}
	
	public static int[] convertToBinary(int a) {
		int[] binary = new int[32];
		int index = 0;
		while (a > 0) {
			binary[index] = a % 2;
			a /= 2;
			index++;
		}
		return binary;
	}
	
	public static void printBinary(int[] binary) {
		for (int i = 31; i >= 0; i--) {
			System.out.printf("%d", binary[i]);
		}
		System.out.println();
	}
	
}


Measured memory_bytes: 86192
#include <stdio.h>

int n,k,a,index;

int main() {
	scanf("%d%d",&n,&k);
	k--;
	for(int i = 0; i < n; i++) {
		scanf("%d",&a);
		if(a==1) index = i;
	}
	int ans = 0;
	if(index>0) {
		ans += (index+k-1)/k;
		index = ans*k;
	}
	ans += (n+k-2-index)/k;
	printf("%d\n",ans);
}


Measured memory_bytes: 128
// https://atcoder.jp/contests/abc160/tasks/abc160_e

use proconio::fastout;
use proconio::input;

#[fastout]
fn main() {
    input! {
        x: usize, y: usize, a: usize, b: usize, c: usize,
        mut ps: [u64; a],
        mut qs: [u64; b],
        mut rs: [u64; c],
    }
    ps.sort_unstable_by(|n, m| m.cmp(n));
    qs.sort_unstable_by(|n, m| m.cmp(n));
    for &p in &ps[..x] {
        rs.push(p);
    }
    for &q in &qs[..y] {
        rs.push(q);
    }
    rs.sort_unstable_by(|n, m| m.cmp(n));
    let ans: u64 = rs[..x + y].iter().sum();
    println!("{}", ans);
}


Measured memory_bytes: 8756
import sys
input = sys.stdin.readline

N = int(input())
wsv = [tuple(map(int, input().split())) for _ in range(N)]
wsv.sort(key=lambda t: t[0]+t[1])
dp = [[0]*(2*10**4+1) for _ in range(N+1)]

for i in range(N):
    w, s, v = wsv[i]
    
    for j in range(2*10**4+1):
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])
        
        if s>=j and j+w<=2*10**4:
            dp[i+1][j+w] = max(dp[i+1][j+w], dp[i][j]+v)

print(max(dp[N]))

Measured memory_bytes: 191512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    ll n; int m; cin >> n >> m;
    VL a(m); cin >> a;
    ll sum = accumulate(all(a), 0LL);
    if (sum <= n)cout << n - sum << "\n";
    else cout << "-1\n";
}

Measured memory_bytes: 3744
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

//===
template<class T>
struct Edge {
    int src, to;
    T cost;

    Edge (int to, T cost):
        src(-1), to(to), cost(cost) {};
    Edge (int src, int to, T cost):
        src(src), to(to), cost(cost) {};

    operator int() const {
        return to;
    };
};

template <class T>
using WeightedGraph = vector<vector<Edge<T>>>;
using UnWeightedGraph = vector<vector<int> >;
//===

template<class T>
vector<T> bfs(WeightedGraph<T> &g, int s) {
    const T INF = numeric_limits<T>::max();
    using P = pair<T, int>;

    vector<T> min_cost(g.size(), INF);
    queue<P> que;
    que.emplace(0, s);

    while (!que.empty()) {
        T cost = que.front().first;
        int pos = que.front().second;
        que.pop();

        if (min_cost[pos] != INF) continue;
        min_cost[pos] = cost;
        for (Edge<T> e:g[pos]) {
            if (min_cost[e.to] <= cost + e.cost) continue;
            que.emplace(cost + e.cost, e.to);
        }
    }

    return min_cost;
};

template<class T>
vector<T> fukugen(WeightedGraph<T> &g, int s) {
    const T INF = numeric_limits<T>::max();
    using P = pair<T, int>;

    vector<T> min_cost(g.size(), INF);
    vector<T> restore(g.size(), -1);
    queue<P> que;
    que.emplace(0, s);

    while (!que.empty()) {
        T cost = que.front().first;
        int pos = que.front().second;
        que.pop();

        if (min_cost[pos] != INF) continue;
        min_cost[pos] = cost;
        for (Edge<T> e:g[pos]) {
            if (min_cost[e.to] <= cost + e.cost) continue;
            que.emplace(cost + e.cost, e.to);
            restore[e.to] = pos;
        }
    }

    return restore;
};

llong n, m;
WeightedGraph<llong> g;
vector<vector<llong>> min_cost;

int main() {
    cin >> n >> m;
    g.resize(n + 1);
    min_cost.resize(n + 1);
    for (int i = 0; i < m; i++) {
        llong a, b;
        cin >> a >> b;
        g[a].emplace_back(b, 1);
    }

    for (int i = 1; i <= n; i++) {
        min_cost[i] = bfs(g, i);
    }

    llong k = 1ll << 60ll;
    llong rest_s, rest_t;
    for (int i = 1; i <= n; i++) {
        for (int v:g[i]) {
            if (k > min_cost[v][i]) {
                k = min_cost[v][i] + 1;
                rest_s = v;
                rest_t = i;
            }
        }
    }

    if (k >= (1ll << 60ll)) {
        cout << -1 << endl;
    }
    else {
        auto rest = fukugen(g, rest_s);

        cout << 0 << endl;
        /*
        cout << k << endl;

        int idx = rest_t;
        while (idx != rest_s) {
            cout << idx << endl;
            idx = rest[idx];
        }
        cout << rest_s << endl;
        */
    }

    return 0;
}


Measured memory_bytes: 8192
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long x,y;
	cin>>x>>y;
	if(x%y==0)
	{
		cout<<"-1";
		return 0;
	} 
	else
	{
		for(long long i=x;;i++)
		if(i%x==0&&i%y!=0)
		{
			cout<<i;
			return 0;
		}
	}
}

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

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

void solve(void){
    int N, M;
    cin >> N >> M;
    if (N > M) {
        cout << min(abs(M - N) + 2, abs(M + N) + 1) << endl;
        return;
    }
    else {
        cout << min(abs(M - N), abs(M+N)+1) << endl;
        return;
    }
}

int main(void){
  solve();
  //cout << "yui(*-v・)yui" << endl;
  return 0;
}


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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    Int(n);
    string st;
    cin >> st;
    
    vi used(30, 1);
    int ans = 1;
    rep(i, st.size()) {
        used[st[i] - 'a']++;
    }

    rep(i, used.size()) {
        ans = (ans * used[i]) % MOD;
    }

    std::cout << ans - 1 << std::endl;

    return 0;
}


Measured memory_bytes: 512
package main

import (
"fmt"
)

func main() {
	var n, x, t int
	fmt.Scan(&n, &x,&t)

	cnt := 0
	sum := 0
	for {
		cnt += t
		sum += x
		if n <=sum {
			break

		}

	}
	fmt.Println(cnt)
}


Measured memory_bytes: 1768
#include <iostream>
#include <string>
#include <array>
#include <algorithm>
#include <vector>

using namespace std;

int f(int num){
    if(num % 2 == 0) return num/2;
    else return 3*num+1;
}
int main() {
    int s;
    vector<int> vec;
    int ans = 0;

    cin >> s;
    while(1) {
        if (find(vec.begin(), vec.end(), s) == vec.end()) {
            ans ++;
            vec.push_back(s);
            s = f(s);
        }else{
            break;
        }
    }
    cout << ans+1;
    return 0;
}

Measured memory_bytes: 3592
#include<stdio.h>
#include<stdlib.h>
void Count(int *,int *,int);
int n,b[2000000];
int main(){
  int i,*a,big=0,*c;
  scanf("%d",&n);
  a=malloc(sizeof(int)*n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    if(big<a[i])big=a[i];
  }
  c=malloc(sizeof(int)*big);
  Count(a,c,big);
  for(i=0;i<n;i++){
    if(i==n-1)printf("%d\n",b[i]);
    else printf("%d ",b[i]);
  }
  free(a);
  free(c);
  return 0;
}

void Count(int *A,int *C,int k){
  int i,j;
  for( i = 0 ;i< k;i++){
       C[i] = 0;
  }

  for( j = 0 ;j<n;j++){
     C[A[j]]++;
  }
  for( i = 1 ;i<= k;i++){
     C[i] = C[i] + C[i-1];
  }
  for( j = n-1 ;j>= 0;j--){
     b[C[A[j]]-1] = A[j];
     C[A[j]]--;
  }
}



Measured memory_bytes: 17064
#include<iostream>
#include<vector>
#include<string>
using namespace std;

int main()
{
	while (1)
	{
		int c;
		cin >> c;
		if (c == 0)break;
		vector<int>a(6);
		for (int b = 0; b < 6; b++)
		{
			a[b] = b + 1;
		}
		int s = 1;
		for (int d = 0; d < c; d++) {
			string e;
			cin >> e;
			vector<int>m(6);
			for (int n = 0; n < 6; n++) {
				m[n] = a[n];
			}
			switch (e[0]) {
			case 'N':a[0] = m[1]; a[1] = m[5]; a[4] = m[0]; a[5] = m[4]; break;
			case 'S':a[1] = m[0]; a[5] = m[1]; a[0] = m[4]; a[4] = m[5]; break;
			case 'E':a[0] = m[3]; a[2] = m[0]; a[3] = m[5]; a[5] = m[2]; break;
			case 'W':a[3] = m[0]; a[0] = m[2]; a[5] = m[3]; a[2] = m[5]; break;
			case 'R':a[1] = m[2]; a[2] = m[4]; a[3] = m[1]; a[4] = m[3]; break;
			case 'L':a[2] = m[1]; a[4] = m[2]; a[1] = m[3]; a[3] = m[4]; break;
			}
			s += a[0];
		}
		cout << s << endl;
	}
}

Measured memory_bytes: 3156
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<algorithm>
#include<string.h>
using namespace std;
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
char s[105],t[205];
int f[105],n,m;
int main(){
	scanf("%s%s",s+1,t+1);
	n=strlen(s+1);
	m=n+n-1;
	fo(i,1,n-1) t[i+n]=t[i];
	int j=0;
	fo(i,2,n){
		while (j&&s[j+1]!=s[i]) j=f[j];
		if (s[j+1]==s[i]) j++;
		f[i]=j;
	}
	j=0;
	fo(i,1,m){
		while (j&&s[j+1]!=t[i]) j=f[j];
		if (s[j+1]==t[i]) j++;
		if (j==n){
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>

int main(){
   int A, B, C, X, Y;
   std::cin >> A >> B >> C >> X >> Y;

   int AB = std::min(A+B, C*2);
   int ans = 0;
   int x = std::min(X, Y);
   int y = x;
   ans += x*AB;
   ans += std::min((X-x)*A+(Y-y)*B, std::max((X-x),(Y-y))*AB);

   std::cout << ans << std::endl;
   return 0;

}


Measured memory_bytes: 256
#D
n, k = map(int, input().split())
r, s, p = map(int, input().split())
hand = sorted([(r, 'r'), (s, 's'), (p, 'p')])
c = input()
ans = list('*'*n)
op = {'r':'p', 's':'r', 'p':'s'}
summ = 0
for i in range(n):
    if i-k >= 0:
        if ans[i-k] != op[c[i]]:
            ans[i] = op[c[i]]
            
            if op[c[i]] == 'r':
                summ += r
            elif op[c[i]] == 's':
                summ += s
            else:
                summ += p
    else:
        ans[i] = op[c[i]]

        if op[c[i]] == 'r':
            summ += r
        elif op[c[i]] == 's':
            summ += s
        else:
            summ += p
print(summ)

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

int cnt[50][26];

int main() {
  int n;
  cin >> n;
  for (int i=0 ; i<n ; i++) {
    string str;
    cin >> str;
    for (int j=0 ; j<str.size() ; j++) {
      cnt[i][(int)(str[j]-'a')] += 1;
    }
  }

  for (int i=0 ; i<26 ; i++) {
    int min_cnt = 100;
    for (int j=0 ; j<n ; j++) {
      min_cnt = min(min_cnt, cnt[j][i]);
    }
    for (int j=0 ; j<min_cnt ; j++) {
      cout << (char)((int)'a' + i);
    }
  }
  cout << endl;
}


Measured memory_bytes: 256
n, m = map(int,input().split())
n_list = []

for i in range(m):
    s, c = map(int,input().split())
    n_list.append([s, c])

n_list = list(tuple(sorted(n_list)))

keta = [-1 for i in range(n)]
flag = 0

for i in range(len(n_list)):
    if keta[n_list[i][0]-1] == -1:
        keta[n_list[i][0]-1] = n_list[i][1]
    elif keta[n_list[i][0]-1] == n_list[i][1]:
        continue
    else:
        flag = 1
        break

if flag == 1 or (n == 3 and keta[0] == 0) or (n == 2 and keta[0] == 0):
    print(-1)
else:
    if len(keta) == 1:
        if keta[0] == -1:
            print(0)
        else:
            print(keta[0])
    elif len(keta) == 2:
        if keta[0] == -1:
            keta[0] = 1
        if keta[1] == -1:
            keta[1] = 0
        print(keta[0]*10 + keta[1])
    else:
        if keta[0] == -1:
            keta[0] = 1
        if keta[1] == -1:
            keta[1] = 0
        if keta[2] == -1:
            keta[2] = 0
        print(keta[0]*100 + keta[1]*10 + keta[2])


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

int main () {
    int x, y, z;
    cin >> x >> y >> z;
    printf("%d %d %d\n", z, x, y);
}  

Measured memory_bytes: 256
#include<stdio.h>
#define N 10000
#define Q 500

int main(){
  int s,t,S[N],T[Q],i,j,count=0;
  
  scanf("%d",&s);

  for(i=0 ; i<s ; i++)scanf("%d",&S[i]);
  
  scanf("%d",&t);
  
  for(i=0 ; i<t ; i++)scanf("%d",&T[i]);
  
  for(i=0;i<t;i++){
    for(j=0;j<s;j++){
      if(S[j]==T[i]){
	count++;
	break;
      }
    }
  }
  printf("%d\n",count);
  return 0; 
}

Measured memory_bytes: 640
a, b, c = [int(i) for i in input().split()]

# a+b-c < -2\sqrt{ab}
# -a-b+c >2\sqrt{ab}
# (c-a-b)**2 >4*a*b and c-a-b>0

if (c-a-b)**2 >4*a*b and c-a-b>0:
    print("Yes")
else:
    print("No")
    

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

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[][] data = new int[M][4];//i, p, y, idx
        for(int i = 0; i < M; i++){
            data[i][0] = i;
            data[i][1] = sc.nextInt();
            data[i][2] = sc.nextInt();
            data[i][3] = 0;
        }
        sc.close();
        Arrays.sort(data, (x, y) -> x[1]==y[1] ? x[2]-y[2] : x[1]-y[1]);
        int a = 0;
        int b = 0;
        for(int i=0; i<M; i++){
            if(data[i][1] != a){
                a = data[i][1];
                b = 0;
            }
            data[i][3] = ++b;
        }
        Arrays.sort(data, (x, y) -> x[0]-y[0]);
        StringBuilder sb = new StringBuilder();
        for(int i=0; i<M; i++){
            int data1 = data[i][1];
            int data3 = data[i][3];
            if(data1 < 10){ sb.append("00000");}
            else if (data1 < 100){ sb.append("0000");}
            else if (data1 < 1000){ sb.append("000");}
            else if (data1 < 10000){ sb.append("00");}
            else if (data1 < 100000){ sb.append("0");}
            sb.append(data1);
            if(data3 < 10){ sb.append("00000");}
            else if (data3 < 100){ sb.append("0000");}
            else if (data3 < 1000){ sb.append("000");}
            else if (data3 < 10000){ sb.append("00");}
            else if (data3 < 100000){ sb.append("0");}
            sb.append(data3);
            sb.append("\n");
        }
        System.out.println(sb.toString());
    }

}


Measured memory_bytes: 97364
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <map>
#include <vector>
#include <set>
#include <algorithm>
#include <sstream>
#include <queue>
#include <cctype>
#include <cmath>
#include <fstream>

using namespace std;

typedef long long ll;
#define REP(i,k) for(int (i)=0;(i)<(k);(i)++)
#define INF ~(1<<31)
#define CLR(a) memset((a),0,sizeof((a)))
#define EPS 1e-9
#define DBG 1
#define D(s,v) if(DBG) cout<<(s)<<": "<<(v)<<endl;
#define DVEC(s,v) if(DBG) {cout<<(s)<<": "; for(int i=0;i<(v).size();i++) cout<<(v)[i]<<" "; cout<<endl;}
#define DARR(s,v,n) if(DBG) {cout<<(s)<<": "; for(int i=0;i<n;i++) cout<<(v)[i]<<" "; cout<<endl;}

int main(){
    ios_base::sync_with_stdio(0);
    int N;

    while(cin>>N){
        vector<int> a;

        for(int i=0;i<N;i++){
            int x; cin>>x;
            a.push_back(x);
        }

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

        int A = 0, B = 0;
        for(int i=0;i<a.size();i++){
            if(i%2==0) A+= a[i];
            else B+=a[i];
        }
        cout<<A-B<<endl;
    }
}

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

#define ll long long
#define sz 200100
ll height[sz],beauty[sz],dp[sz],tree[4*sz];

///dp[i] means maximum possible sum of beauty for [i , n] interval if I keep this ith flower.
///Here, in segment tree at index h[i] I'll keep maximum possible sum of beauty for interval [i,n] if I keep the ith flower.

void Update(ll node,ll b,ll e,ll pos,ll val)
{
    if(pos<b || pos>e)
        return;
    if(b==pos && e==pos){
        tree[node] = val;
        return;
    }
    ll mid = (b+e)>>1;
    ll lft = node<<1;
    ll rgt = 1+lft;
    Update(lft , b , mid , pos , val);
    Update(rgt , mid+1 , e , pos , val);
    tree[node] = max(tree[lft] , tree[rgt]);
}

ll Query(ll node,ll b,ll e,ll i,ll j)
{
    if(j<b || i>e)
        return 0LL;
    if(b>=i && e<=j)
        return tree[node];
    ll mid = (b+e)>>1;
    ll lft = node<<1;
    ll rgt = 1+lft;
    ll p1 = Query(lft , b , mid , i , j);
    ll p2 = Query(rgt , mid+1 , e , i , j);
    return max(p1 , p2);
}

int main()
{
    ll i,j,k,n,ans=0;
    cin>>n;
    ll limit = n+5;
    for(i=1 ; i<=n ; i++)   cin>>height[i];
    for(i=1 ; i<=n ; i++)   cin>>beauty[i];

    for(i=n ; i>=1 ; i--){
        ll mxsofar = Query(1 , 1 , limit , height[i]+1 , limit);
        dp[i] = beauty[i] + mxsofar;
        Update(1 , 1 , limit , height[i] , dp[i]);
        ans = max(ans , dp[i]);
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 12356
#include<bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, k, l;
    cin >> n >> k >> l;
    vector<vector<int> >g1(n + 3), g2(n + 3);
    for(int i = 1; i <= k; i++){
        int u, v;
        cin >> u >> v;
        g1[u].push_back(v);
        g1[v].push_back(u);
    }
    for(int i = 1; i <= l; i++){
        int u, v;
        cin >> u >> v;
        g2[u].push_back(v);
        g2[v].push_back(u);
    }
    queue<int>q;
    vector<int>roadpos(n + 3, -1), railpos(n + 3, -1);
    int cnt = 0;
    for(int i = 1; i <= n; i++){
        if(roadpos[i] == -1){
            roadpos[i] = cnt;
            q.push(i);
            while(!q.empty()){
                int u = q.front();
                q.pop();
                for(int j = 0; j < g1[u].size(); j++){
                    int v = g1[u][j];
                    if(roadpos[v] == -1){
                        roadpos[v] = cnt;
                        q.push(v);
                    }
                }
            }
            cnt++;
        }
    }
    cnt = 0;
    for(int i = 1; i <= n; i++){
        if(railpos[i] == -1){
            railpos[i] = cnt;
            q.push(i);
            while(!q.empty()){
                int u = q.front();
                q.pop();
                for(int j = 0; j < g2[u].size(); j++){
                    int v = g2[u][j];
                    if(railpos[v] == -1){
                        railpos[v] = cnt;
                        q.push(v);
                    }
                }
            }
            cnt++;
        }
    }
    map<pair<int, int>, int>mp;
    for(int i = 1; i <= n; i++){
        mp[{roadpos[i], railpos[i]}]++;
    }
    for(int i = 1; i <= n; i++){
        cout << mp[{roadpos[i], railpos[i]}] << ' ';
    }
    return 0;
}

Measured memory_bytes: 30100
using System;
using System.Collections.Generic;
namespace std{
    class Test {
        static void Main(string[] args) {
       int i = 0;
       int tmp;
             List<int> ary_x = new List<int>();
               List<int> ary_y = new List<int>();
            while(true) {
        //        var input = int.Parse(Console.ReadLine().Split(' '));
                    var inp = Console.ReadLine().Split(' ');
                    var x = int.Parse(inp[0]);
                    var y = int.Parse(inp[1]);
            
                if(x == 0 && y == 0) break;
               if (x > y) {
                /*   tmp = input[0];
                   input[0] = input[1];
                   input[1] = tmp;*/
                   
                   ary_x.Add(y);
                   ary_y.Add(x); 
               } else {
                ary_x.Add(x);
                ary_y.Add(y);
               }
            //    if(x == 0 && y == 0) break;
            
            }
           for (i = 0; i < ary_x.Count; i++) {
               Console.WriteLine("{0} {1}",ary_x[i], ary_y[i]);
              
           } 
        }
        
    }
}


Measured memory_bytes: 15844
import java.util.*;

public class Main {
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		String S = sc.nextLine();
		sc.close();
		char[] sa = S.toCharArray();
		int N = sa.length;
		int cindex = -1;
		boolean result = false;
		for(int i = 0; i < N; i++)
		{
			if(sa[i] == 'C')
			{
				cindex = i;
				break;
			}
		}
		if(cindex != -1)
		{
			for(int i = cindex + 1; i < N; i++)
			{
				if(sa[i] == 'F')
				{
					result = true;
					break;
				}
			}
		}
		if(result) System.out.println("Yes");
		else System.out.println("No");
	}
}

Measured memory_bytes: 10192
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        int n;
        Scanner scan = new Scanner(System.in);
        n = scan.nextInt();
        int v[] = new int [n];
        for(int i = 0; i < n; i++)
            v[i] = scan.nextInt();
        int ans = -100000000;
        for(int a : v){
            for(int b:v){
                ans = Math.max(ans,Math.abs(a-b));
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 22612
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,m,i,k=0,a[200000],sum=0;
    cin>>n>>m;
    for(i=0; i<n; i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    if(n<=m)
    {
        cout<<0;
    }
    else{
        k = n-m;
        for(i=0; i<k; i++)
        {
            sum = sum+a[i];
        }
        cout<<sum;
    }

}


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        int[] arr = Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();
        int k = arr[0];
        int n = arr[1];   
        int[] arrTwo = Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();
        int max = k + arrTwo[0] - arrTwo[n - 1];
        for (int i = 0; i < n - 1; i++)
        {
            int deruta = arrTwo[i + 1] - arrTwo[i];
            if (deruta > max) max = deruta;
        }
        Console.WriteLine(k - max);
    }


  

}



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

int main(){
	int a[4], b[4];

	while(cin >> a[0]){
		for(int i = 1; i < 4; i++){
			cin >> a[i];
		}
		for(int i = 0; i < 4; i++){
			cin >> b[i];
		}

		int hit = 0, blo = 0;
		for(int i = 0 ; i < 4; i++){
			for(int j = 0; j < 4; j++){
				if(a[i] == b[j]){
					if(i == j){
						hit++;
					}
					else{
						blo++;
					}

				}
			}
		}

		cout << hit << " " << blo << endl;
	}

}

Measured memory_bytes: 1160
#include <stdio.h>
int main()
{
    char s1[100];
    scanf("%s",s1);
    int i=0,cn=0;
    while(s1[i]!='\0'){
        if(s1[i]=='2'){
            cn++;
        }
        i++;
    }
    printf("%d\n",cn);
    return 0;
}


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

typedef long long ll;
char c[4][4];

int main(){
  int n;
  cin>> n;
  vector<ll>a(n); 
  for(int i=0; i<n; i++){
    cin >> a[i];
  }
  ll ans = 0;
  for(int i=0; i<n; i++){
    if(i+1<n&&a[i]==a[i+1]){
      while(a[i]==a[i+1])i++;
    }
    if(i+1<n&&a[i] < a[i+1]){
      while(a[i] <= a[i+1]){
	i++;
      }
    }else if(i+1<n&&a[i] >= a[i+1]){
      while(a[i] >= a[i+1])i++;
    }
    ans++;
  }
  cout<< ans << endl;
  return 0;
}


Measured memory_bytes: 1024
import java.io.PrintWriter
import java.util.*

fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val arr = readLine()!!.split(" ").map(String::toInt)
  val ans = mutableSetOf<Int>()
  for (i in n downTo 1) {
    var j = i * 2
    var m = 0
    while (j <= n) {
      if (ans.contains(j)) {
        ++m
      }
      j += i
    }
    m %= 2
    // debug(i, m)
    if (m != arr[i - 1]) {
      ans.add(i)
    }
  }
  println(ans.size)
  println(ans.toList().joinToString(separator = " "))
}

fun debug(vararg objs: Any) {
  System.err.println(Arrays.deepToString((objs)))
}

Measured memory_bytes: 97408
import sys

INPUT = lambda: sys.stdin.readline().rstrip()
MAP = lambda: map(int, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))

sys.setrecursionlimit(10 ** 9)


def main():
    N, M, C = MAP()
    B = LIST()
    A = [LIST() for _ in range(N)]

    cnt = 0
    for i in range(N):
        if sum([a*b for a, b in zip(A[i], B)]) + C > 0: cnt += 1

    print(cnt)


if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
#include <iostream>
//#include <vector>
//#include <string>
//#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1

int main() {
    LL a;
    LL ans;
    cin >> a;
    ans = a+a*a+a*a*a;
    cout << ans << endl;

    return 0;
}


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

int main(){
  string s, t;
  cin >> s >> t;
  cout << t + s << endl;
}


Measured memory_bytes: 3620
# coding: utf-8
# Your code here!

h1, m1, h2, m2, k = map(int, input().split())

# print(h1, m1, h2, m2, k)

start_m = (60 * h1) + m1
end_m = (60 * h2) + m2
okiteiru = end_m - start_m

# print(start_m)
# print(end_m)
# print(okiteiru)

print(okiteiru - k)


Measured memory_bytes: 9160
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp make_pair
#define F first
#define S second
#define pf pop_front
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
typedef long long ll;
const ll mod=1e9+7;
const ll maxn=200005;
const ll inf=1e9+7;
int n;
int main()
{
    string s;
    while(cin>>n>>s)
    {
        rep(i,s.size())
        {
            cout<<char((s[i]-'A'+n)%26+'A');
        }
        cout<<"\n";
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int gcd(int a,int b){
   if(b==0){
       return a;
   }else{
       return gcd(b,a%b);
   }
}
int main()
{
   int N;
   cin >> N;
   int first[100000] = {};
   int last[100000] = {};
   int A[100000] = {};
   int a[100000] = {};
   for(int i=0;i<N;i++){
       cin >> A[i];
       a[i] = A[i];
   }
   reverse(a,a+N);
for(int i=0;i<N;i++){
first[i+1] = gcd(A[i],first[i]);
}
for(int i=0;i<N;i++){
last[i+1] = gcd(a[i],last[i]);
}
int ans = 0;
   for(int i=0;i<=N;i++){
       ans = max(ans,gcd(first[i],last[N-1-i]));
   }
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> A(1e5+1);
	int ans = 0;
	for(int i=0;i<N;i++){
		int a;
		cin >> a;
		if(A[a]==0)ans++;
		A[a]++;
	}
	int cnt = 0;
	for(int i=0;i<1e5+1;i++){
		if(A[i]>0&&A[i]%2==0)cnt++;
	}
	if(cnt%2==1)ans -=1;
	cout << ans << endl;
	
	/*
	0 0
	1 1
	2 2
	3 1
	4 2
	*/
}

Measured memory_bytes: 640
var toInt = x=>parseInt(x,10);
var toIntArr = arr=>arr.map(x=>toInt(x));
var abs = x=>x>0?x:-x;
function min(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]<val)val = rest[i];return val}
function max(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]>val)val = rest[i];return val}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
 
function Main(input){
	var input = input.split('\n');
	var s = input[0];
	var k = toInt(input[1]);
	var chou = 5*Math.pow(10,15);

	while(s[0]==1){
		if(k===1){
			console.log(1);
			return 0;
		}
		s = s.slice(1);
		k--;
	}
	console.log(s[0]);

}

Measured memory_bytes: 21064
#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;

int count(int N){
    int res = 0;
    for(int d = 1; d*d<=N; d++){
        if(N % d == 0){
            res += 1;
            if (d*d != N) res += 1;
        }
    }
    return res;
}


int main(){
    int N; cin >> N;
    int ans = 0;

    rep1(C,N-1){
        int AB = N-C;
        ans += count(AB);
    }
    cout << ans << endl;
}


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

#define endl ("\n")

int main()
{
    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cout << fixed;
    cout.precision(10);
    // Those who cannot acknowledge themselves, will invaraibly fail
    

    string s;
    cin >> s;
    for(int i = 0;i < s.size();i++)
    {
        cin >> s;
    }
    sort(s.begin(), s.end());
    if(s[0] == s[1] and s[2] == s[3] and s[1] != s[2])
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define ft first
#define sd second
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<long long,long long> pll;

int main() {
    fastIO;
    int n, aux, rta = 0;
    cin >> n;
    int a[n], b[n], c[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < n; i++){
        cin >> b[i];
    }
    for(int i = 0; i < n-1; i++){
        cin >> c[i];
    }

    rta += b[a[0]-1];
    for(int i = 1; i < n; i++){
        rta += b[a[i]-1];
        if(a[i] - a[i-1] == 1){
            rta += c[a[i-1]-1];
        }
    }
    cout << rta << endl;
    return 0;
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <algorithm>
#include <string>
using namespace std;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int a, b;
    cin >> a >> b;
    cout << (a + b + 1) / 2 << endl;
    return 0;
}

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

int main(){
	int N;
		
	while(1){
		int S = 0;
		cin>>N;
		if(N == 0) break;
		for(int i = 1; i * i < N;i++){
			if(N%i == 0){
				S += i;
				S += N/i;
			}
		}
		if(S - N == N) cout<<"perfect number"<<endl;
		else if(S - N > N)cout<<"abundant number"<<endl;
		else if(S - N < N)cout<<"deficient number"<<endl; 
	}
}



Measured memory_bytes: 3004
#include <iostream>
#include <cassert>
#include <algorithm>
#include <string>
#include <vector>
#include <tuple>
#define REP(i,k,n) for(int(i)=(k);(i)<(n);++(i))
using namespace std;

int a,b;

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

  int n = b - a;

  int x = 0;                    // h + a
  REP(i,1,n) x += i;

  int h = x - a;
  cout << h << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long
#define lfl long double

lin h,w,n;
lin y,x;
string s,t;

bool solve(char pos, char neg, lin mx, lin cr)
{
    bool bt = true;
    lin pc = 0;
    lin nc = 0;

    lin lmn = 0;
    lin lmx = mx - 1;

    for (int i = n - 1; i >= 0; i--)
    {
        if(!bt && (t[i] == pos || t[i] == neg))
        {
            lmx -= pc;
            lmn += nc;

            if(lmn > lmx)
                return false;

            pc = 0;
            nc = 0;
            bt = true;
        }

        if(bt && (t[i] == pos || t[i] == neg))
        {
            if(t[i] == pos)
                pc++;
            else if(t[i] == neg)
                nc++;
        }

        if(bt && (s[i] == pos || s[i] == neg))
        {
            lmx += nc;
            lmn -= pc;
            lmx = min(lmx, mx - 1);
            lmn = max(lmn, (lin)0);

            pc = 0;
            nc = 0;
            bt = false;
        }

        if(!bt && (s[i] == pos || s[i] == neg))
        {
            if(s[i] == pos)
                pc++;
            else if(s[i] == neg)
                nc++;
        }
    }

    if(!bt)
    {
        lmx -= pc;
        lmn += nc;

        if(lmn > lmx)
            return false;
    }
    else
    {
        lmx += nc;
        lmn -= pc;
        lmx = min(lmx, mx - 1);
        lmn = max(lmn, (lin)0);
    }

    return lmn <= cr && cr <= lmx;
}

bool solve()
{
    return
        solve('D', 'U', h, y) &&
        solve('R', 'L', w, x);
}

int main(void)
{
    cin >> h >> w >> n >> y >> x >> s >> t;
    y--;
    x--;

    bool res = solve();
    if(res)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}


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

int main(){
  int H, W;
  while(true){
    cin >> H >> W;
    if(H==0 && W==0){
      break;
    }
    for(int i=1;i<=H;i++){
      for(int j=1;j<=W;j++){
        if(i==1 || i==H || j==1 || j==W){
          cout << "#";
        } else {
          cout << ".";
        }
      }
      cout << endl;
    }
    cout << endl;
  }
}



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


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

    queue<long int> q;

    for(int i=1;i<=9;i++)
    	q.push(i);

    long int ans;
    for(int i=0;i<t;i++){
    	ans = q.front();
    	q.pop();
    	if(ans % 10 != 0)
    		q.push(10*ans + ans%10 - 1 );
    	q.push(10*ans + ans%10);
    	if(ans % 10 != 9)
    		q.push(10*ans + ans%10 + 1);

    }

    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
/*ITS FUCKING O(N) now
GET ACCEPTED FOR FUCK'S SAKE*/
#define _USE_MATH_DEFINES
 
#include <cmath>

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

long long powerexp(long long base, long long exp, int mod) {
   long long res = 1;
   while (exp > 0) {
      if (exp % 2 == 1)
         res= (res * base) % mod;
      exp = exp >> 1;
      base = (base * base) % mod;
   }
   return res;
}
int gcd(int a, int b)
{
    int c = a % b;
    while(c != 0)
    {
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}
void PrintVector(vector<long long int> v,long long int n)
{
 
    for(int i=v.size()-1;i>=0;i--)
    {
        cout<<v[i]<<" ";
    }
    cout<<endl;
}
void Takevector(vector<long long int> &v,long long int n)
{
  for(long long int i=0;i <n;i++)
  { long long int number;
    cin>>number;
    v.push_back(number);
  }
}
typedef long long int ll;
typedef vector<long long int> vi;

#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define scl(x)         ll x;       scanf("%lld", &x);
#define scll(x, y)     ll x, y;    scanf("%lld %lld", &x, &y);
#define sclll(x, y, z) ll x, y, z; scanf("%lld %lld %lld", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define rep(i, x, y)   for (__typeof(x) i = x; i <= y; i ++)
#define repi(i, x, y)  for (__typeof(x) i = x; i >= y; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
#define nl cout<<"\n";
int min(int x, int y)  
{  
    return (x < y)? x: y;  
      
}  
  
int main()
{
  int flag=0;
  ll sum=0;
  int flag1=1;
  ll tot=0;
  int ans=0;
  map<int,int>m;
  vi v;
  set<int>st;
  string s;
  scl(x);
  ll c=100;
  while(c<x)
  {
    c+=c/100;
    tot++;
  }
   cout<<tot;
    return 0;
}

Measured memory_bytes: 3704
# C
n = int(input())
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))

max_candy = 0
for i in range(n):
    candy = sum(a1[0:i+1]) + sum(a2[i:n])
    if max_candy < candy:
        max_candy = candy
print(max_candy)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int n,m;
const int N=2010;
int a[N];
bitset <N*N> f;
int main(){
	scanf("%d",&n);
	f[0]=1;
	for(int i=1;i<=n;++i)scanf("%d",&a[i]),m+=a[i];
	for(int i=1;i<=n;++i) f|=f<<a[i];
	for(int i=(m+1)/2;i<=m;++i){
		if(f[i]){
			printf("%d\n",i);
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 1792