akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

constexpr int MOD = 1000000007;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

int N;
int T[101010], A[101010];

int main() {
    cin >> N;
    for (int j = 0; j < N; ++j) {
        cin >> T[j];
    }
    for (int j = 0; j < N; ++j) {
        cin >> A[j];
    }

    int h[101010];
    fill(h, h+N, -1);

    h[0] = T[0];
    for (int j = 1; j < N; ++j) {
        if (T[j] != T[j-1]) {
            h[j] = T[j];
        }
    }

    if (h[N-1] != -1 && h[N-1] != A[N-1]) {
        cout << 0 << endl;
        return 0;
    }

    h[N-1] = A[N-1];
    for (int j = 1; j < N; ++j) {
        if (A[N-1-j] != A[N-j]) {
            if (h[N-1-j] != -1 && h[N-1-j] != A[N-1-j]) {
                cout << 0 << endl;
                return 0;
            }
            h[N-1-j] = A[N-1-j];
            if (h[N-1-j] > T[N-1-j]) {
                cout << 0 << endl;
                return 0;
            }
        }
    }

    LL ans = 1LL;
    for (int j = 0; j < N; ++j) {
        if (h[j] == -1) {
            ans = (ans * min(min(A[j-1], A[j+1]), min(T[j-1], T[j+1]))) % MOD;
        }
    }
    cout << ans << endl;



    return 0;
}


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

#define MIN(a,b) ((a)<(b)?(a):(b))

int main() {
	string s;
	cin >> s;
	string ans="";
	ans += s[0];
	ans += to_string(s.size()-2);
	ans += s.back();
	cout << ans;

	return 0;
}

Measured memory_bytes: 256
def solve():
    N = int(input())
    ans = []

    left = 0
    right = N + 1
    while right - left > 1:
        mid = (left + right) // 2
        success, elems = calcElements(mid, N)
        if success:
            ans = elems
            right = mid
        else:
            left = mid
    print(*ans,sep='\n')

def calcElements(max_value, N):
    sm = 0
    elems = []
    for k in range(max_value, 0, -1):
        if sm + k <= N:
            sm += k
            elems.append(k)
            if sm == N:
                return (True, elems)
    
    return (False, elems)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 3824
#include<bits/stdc++.h>
using namespace std;
long long int a,b,aa,bb,n,kk,ss,kake;

int main(){
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a >> b;
        if(i==0){
            aa=a;
            bb=b;
        }else{
            if(aa%a==0)kk=aa/a;
            else kk=aa/a+1;
            if(bb%b==0)ss=bb/b;
            else ss=bb/b+1;
            kake=max(kk,ss);
            aa=a*kake;
            bb=b*kake;

        }
    }

    cout << aa+bb << endl;
    //cin >> a;
return 0;
}


Measured memory_bytes: 256
// tsukasa_diary's programing contest code template
#include <bits/stdc++.h>
using namespace std;
#define TSUKASA_DIARY_S_TEMPLATE
// define
#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)
#define allof(a) (a).begin(),(a).end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) int((a).size())
#define cauto const auto
// typedef
typedef long long lint;
typedef double Double;
typedef pair< int, int > pii;
template< typename T > using Vec = vector< T >;
template< typename T > using Matrix = Vec< Vec< T > >;
template< typename T > using USet = unordered_set< T >;
template< typename T, class C > using MyUSet = unordered_set< T, C >;
template< typename T, typename F > using UMap = unordered_map< T, F >;
template< typename T, typename F, class C > using MyUMap = unordered_map< T, F, C >;
// hash
class PiiHash { public: size_t operator () (const pii& p) const { return (p.first << 16) | p.second; } };
// popcount
inline int POPCNT(int x) { return __builtin_popcount(x); }
inline int POPCNT(lint x) { return __builtin_popcount(x); }
// inf
const int iINF = 1L << 30;
const lint lINF = 1LL << 60;
// eps
const Double EPS = 1e-9;
const Double PI = acos(-1);
// inrange
template< typename T >
inline bool in_range(T v, T mi, T mx) { return mi <= v && v < mx; }
template< typename T >
inline bool in_range(T x, T y, T W, T H) { return in_range(x,0,W) && in_range(y,0,H); }
// neighbor clockwise
const int DX[4] = {0,1,0,-1}, DY[4] = {-1,0,1,0};
const int DX_[8] = {0,1,1,1,0,-1,-1,-1}, DY_[8] = {-1,-1,0,1,1,1,0,-1};
// variable update
template< typename T > inline void modAdd(T& a, T b, T mod) { a = (a + b) % mod; }
template< typename T > inline void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > inline void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > inline void maxUpdate(T& a, T b) { a = max(a, b); }
// converter
template< typename F, typename T >
inline void convert(F& from, T& to) {
	stringstream ss;
	ss << from; ss >> to;
}

class EnumBridge {
private:
	int n;
	Vec< Vec< int > > adj;
	
public:
	EnumBridge(int __n) : n(__n), adj(__n, Vec< int >()) {}
	
	void addEdge(int u, int v) {
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	
	void dfs(int v, int p, int& cnt, Vec< int >& pos, Vec< int >& link, Vec< pii >& bridge) {
		if (pos[v] != -1) {
			link[p] = min(link[p], pos[v]);
			return;
		}
				
		pos[v] = link[v] = cnt; ++cnt;
		
		for (int u : adj[v]) {
			if (u == p) continue;
			dfs(u, v, cnt, pos, link, bridge);
			link[v] = min(link[v], link[u]);
		}
		
		if (p != -1 && pos[v] == link[v]) bridge.push_back(pii(min(p, v), max(p, v)));
	}
	
	Vec< pii > run() {
		Vec< pii > res;
		int cnt = 0;
		Vec< int > pos(n, -1);
		Vec< int > link(n, n);
		for_(v,0,n) dfs(v, -1, cnt, pos, link, res);
		return res;
	}
};

int main() {
	int n, m;
	cin >> n >> m;
	
	EnumBridge eb(n);
	for_(i,0,m) {
		int u, v;
		cin >> u >> v;
		eb.addEdge(u, v);
	}
	Vec< pii > b = eb.run();
	sort(allof(b));
	for (pii p : b) cout << p.first << " " << p.second << endl;
}

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

void solve() {
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        ans += x - 1;

    }
    cout << ans;
}

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


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


i64 N, R;


int main() {
  cin >> N >> R;
  if (N >= 10) {
    cout << R << endl;
  } else {
    cout << R + (100 * (10 - N)) << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if ((A == B and A != C) or ((B == C) and A != B) or ((A == C) and B != A)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

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)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define VIN(v) for(auto&elem_: (v) )cin>>elem_
#define VOUT(v, sep) for(_loop_int idx=0; idx<(_loop_int)v.size(); idx++) {cout<<v[idx]; if(idx<v.size()-1) cout<<sep;} cout<<endl

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(debugidx,v.size())cout<<" "<<v[debugidx];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(debugidx,n)cout<<" "<<v[debugidx];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
const int IINF = numeric_limits<int>::max()/2-1;
const ll LINF = numeric_limits<ll>::max()/2-1;
#define FIX(a) ((a)%MOD+MOD)%MOD

int n;
vector<vector<pii>> g;
vi ans; //color //偶数=0, 奇数=1
void dfs(int now, int prev, ll sumw){

    int sz = g[now].size();
    REP(i,sz){
        if(g[now][i].first == prev) continue;
        dfs(g[now][i].first, now, sumw + g[now][i].second);
    }

    ans[now] = (sumw%2==0) ? 0 : 1;
}
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin>>n;
    g.resize(n);
    ans.resize(n,-1);
    
    REP(i,n-1){
        int u,v,w;
        cin>>u>>v>>w;
        u--;
        v--;
        g[u].emplace_back(pii(v,w));
        g[v].emplace_back(pii(u,w));
    }

    dfs(0,-1,0LL);
    //DEBUG_VEC(ans);
    VOUT(ans,endl);
    //cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9728
#include<stdio.h>
int main(void)
{
	int n,c,p[100],x,y,i;
	scanf("%d %d",&n,&c);
	y=0;
	for(i=0;i<c;i++){
		scanf("%d",&p[i]);
		y=y+p[i];
	}
	x=y/(n+1);
	if(y%(n+1)!=0){
		printf("%d\n",x+1);
	}
	else{
		printf("%d\n",x);
	}
	return 0;
}
	


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll MOD = 1e9+7;
ll LLINF = 1LL << 60;
int INF = INT_MAX;

int main(){
    ll n; cin>>n;
    vector<vector<ll>> a(n,vector<ll>(n,0));
    rep(i,0,n){
        rep(j,0,n){
            cin>>a[i][j];
        }
    }
    ll ans=0;
    rep(i,0,n-1){
        rep(j,i+1,n){
            bool ok=true;
            rep(k,0,n){
                if(i==k or j==k) continue;
                if(a[i][k]+a[k][j]==a[i][j]){
                    ok=false;
                }else if(a[i][k]+a[k][j]<a[i][j]){
                    cout<<-1<<endl;
                    return 0;
                }
            }
            if(ok) ans+=a[i][j];
        }
    }

    cout<<ans<<endl;

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a=1,min,N,K;
  cin >> N;
  cin >> K;
  for(int k=0;k<N+1;k++){
    for(int i=0;i<k;i++){
      a*=2;
    }
    for(int j=0;j<N-k;j++){
      a+=K;
    }
    if(k==0||a<min)
      min=a;
    a=1;
  }
  cout << min << endl;
}

Measured memory_bytes: 256
require 'set'

class UnionFind
	def initialize
		@obj_to_node = {}
	end

	def add(obj)
		@obj_to_node[obj] ||= Node.new(obj)
	end

	def size(x = nil)
		x ? @obj_to_node[x].root.size : @obj_to_node.size
	end

	class Node
		def initialize(obj)
			@obj = obj
			@parent = self
			@size = 1
			@rank = 0
		end

		def root
			return self if @parent == self
			@parent = @parent.root
		end	

		attr_accessor :parent, :size, :rank, :obj
	end

	def union(x, y)
		u = (@obj_to_node[x] ||= Node.new(x)).root
		v = (@obj_to_node[y] ||= Node.new(y)).root
		return if u == v
		if u.rank > v.rank
			v.parent = u
			u.size += v.size
		elsif v.rank > u.rank
			u.parent = v
			v.size += u.size
		else
			u.parent = v
			v.rank += 1
			v.size += u.size
		end
	end

	def same?(x, y)
		return false unless u = @obj_to_node[x]
		return false unless v = @obj_to_node[y]
		u.root == v.root
	end

	def root(x)
		(@obj_to_node[x] ||= Node.new(x)).root
	end
end

loop do
	n, p1, p2 = gets.split.map &:to_i
	break if n == 0 && p1 == 0 && p2 == 0
	m = p1 + p2

	yes = []
	no = []
	n.times do
		a, b, yes_no = gets.chomp.split
		pair = [a.to_i, b.to_i]
		(yes_no == "yes" ? yes : no) << pair
	end

	if p1 == 0
		puts "end"
		next
	end

	if p2 == 0
		(1..m).each {|i| puts i}
		puts "end"
		next
	end

	if p1 == p2
		puts "no"
		next
	end
	
	uf = UnionFind.new	
	yes.each do |a, b|
		uf.union(a, b)
	end

	neighbour = {}
	no.each do |a, b|
		r1, r2 = uf.root(a).obj, uf.root(b).obj
		(neighbour[r1] ||= []) << r2
		(neighbour[r2] ||= []) << r1
		neighbour[r1].each{|r3| uf.union(r2, r3) }
		neighbour[r2].each{|r3| uf.union(r1, r3) }
	end
	
	roots = (0..m).map{|i| uf.root(i)} 

	pairs = []
	in_pair = []
	no.each do |a, b|
		next if a == b
		u = roots[a]
		v = roots[b]
		next if in_pair.include?(u)
		in_pair << u
		in_pair << v
		pairs << [u, v]
	end

	roots.shift

	#class UnionFind::Node; def to_s; size; end; end

	(roots.compact.uniq - in_pair).each{|r| pairs << [r, nil]}

	hash = {0 => []}
	pairs.each do |u, v|
		new_hash = {}		
		hash.each do |k, cs|
			l = k + u.size
			new_hash[l] = (new_hash[l] ? [nil] : cs + [u])
			if v
				l = k + v.size
				new_hash[l] = (new_hash[l] ? [nil] : cs + [v])
			else
				l = k
				new_hash[l] = (new_hash[l] ? [nil] : cs)
			end
		end
		hash = new_hash
	end
	#p hash[101]
	
	if !hash[p1] || hash[p1].include?(nil)
		puts 'no'
	else
		nodes = {}
		(1..m).each do |i|
			(nodes[uf.root(i)] ||= []) << i
		end
		puts hash[p1].map{|r| nodes[r]}.flatten.sort
		puts 'end'
	end
end

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

using namespace std;

int main (){
  int N,M,count,max;
  cin >> N;
  max = 0;
  count = 0;
  
  vector<string> vecN(N);
  for(int i = 0; i < N; i++){
    cin >> vecN.at(i);
  } 
  cin >> M;
  vector<string> vecM(M);
  for(int i = 0; i < M; i++){
    cin >> vecM.at(i);
  }
  for(int i = 0; i < N; i++){
    count = 0;
    for(int j = 0; j < N; j++){
      if(vecN.at(i) == vecN.at(j)){count++;}
    }
    for(int k = 0; k < M; k++){
      if(vecN.at(i) == vecM.at(k)){count--;}
    }
    if(max < count){max = count;}
  }
  cout << max << endl;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b;
int main()
{
	cin>>a>>b;
	if(((a+b)%3==0)||(a%3==0)||(b%3==0))
	cout<<"Possible"<<endl;
	else cout<<"Impossible"<<endl;
	return 0;
}

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

int main()
{
    int n, k;
    cin >> n >> k;

    map<int, int> num_map;
    rep(i, 0, n)
    {
        int a;
        cin >> a;
        num_map[a]++;
    }

    vector<pair<int, int>> cnt_num;
    for (auto nm: num_map)
        cnt_num.emplace_back(nm.second, nm.first);

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

    int ans = 0;
    rep(i, 0, cnt_num.size())
    {
        if (k <= 0) ans += cnt_num[i].first;
        k--;
    }

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

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

int main(){
    long long N;
    std::cin >> N;
    
    if(N % 2 == 1){
        std::cout << 0 << std::endl;
    }else{
        long long cnt = 0;
        long long cur = 1;
        N /= 2;
        while(N){
            N /= 5;
            int tmp = N % 5;
            cnt += tmp * cur;
            cur = cur * 5 + 1;
        }
        
        
        std::cout << cnt << std::endl;
    }
    
    return 0;
}



Measured memory_bytes: 256
//aoj 0033 Ball
//10个球下落，分2个管道走，要求2个管道里面自底向上数字要??
#include<cstdio>
using namespace std;

int boll[15];
int dig[2];

//bool dfs(int d)//dfs的参数越少越好，不用考?管道分支
//{
//    if(d==10) return true;//放完了
//    int tmp;
//    for(int i=0; i<2; ++i)
//    {
//        if(boll[d]>dig[i])
//        {
//            tmp = dig[i];
//            dig[i] = boll[d];
//            if(dfs(d+1)) return true;
//            dig[i] = tmp;
//        }
//    }
//    return false;
//}

bool dfs(int bi, int di)//?里是考?了管道分支的
{
    if(bi==10) return true;//放完了
    int tmp = dig[di];
    if(boll[bi]>dig[di]) dig[di] = boll[bi];
    else return false;
    for(int i=0; i<2; ++i)
    {
        if(dfs(bi+1,i)) return true;
    }
    dig[di] = tmp;
    return false;
}

void solve()
{
    dig[0] = dig[1] = -1;
    //少参数版
    //bool ans = dfs(0);
    
    //多参数版
    bool ans = false;
    for(int i=0; i<2; ++i) ans |= dfs(0,i);
    
    printf("%s\n", ans?"YES":"NO");
}

int main()
{
    int n;
    scanf("%d\n", &n);
    while(n--)
    {
        for(int i=0; i<10; ++i) scanf("%d", &boll[i]);
        solve();
    }
    return 0;
}

Measured memory_bytes: 2488
/*
[abc137] D - Summer Vacation
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MAX_N = 1e5;

int N, M;
pii AB[MAX_N];
priority_queue<int> q;

ll solve() {
    sort(AB, AB + N);

    int ans = 0;
    for (int j = M - 1, i = 0; j >= 0; j--) {
        for (; i < N && AB[i].first <= M - j; i++) {
            q.push(AB[i].second);
        }
        if (!q.empty()) {
            ans += q.top();
            q.pop();
        }
    }

    return ans;
}

int main() {
    cin >> N >> M;
    for (int i = 0; i < N; i++) {
        cin >> AB[i].first >> AB[i].second;
    }

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 1660
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#define all(x) (x).begin(),(x).end()
typedef long long ll;
 
using namespace std;
 
int main()
{
    int N;   cin >> N;
    ll mod2 = 1000000007;
    ll ans = 1;
    vector<ll> T(N), A(N), e(N,0), maxt(N);
    for(int i=0; i<N; i++)  cin >> T[i];
    for(int i=0; i<N; i++)  cin >> A[i];
    if(T[N-1] != A[0])  ans = 0;
    e[0] = T[0];
    for(int i=1; i<N; i++){
        if(T[i] > T[i-1]){
            e[i] = T[i];
            maxt[i] = T[i];
        }else   maxt[i] = maxt[i-1];
    }
    if(e[N-1] > 0 && e[N-1] != A[N-1]){
        ans = 0;
    }else{
        e[N-1] = A[N-1];
        for(int i=N-2; i>=0; i--){
            if(A[i] > A[i+1]){
                if(A[i] > maxt[i]){
                    ans = 0;
                }else{
                    e[i] = A[i];
                }
            }
        }
    }
    for(int i=0; i<N; i++){
        if(e[i] == 0){
            ans *= min(A[i],T[i]);
            ans %= mod2;
        }
    }
    cout << ans;
}

Measured memory_bytes: 6392
from collections import Counter
from functools import reduce
from itertools import product
from math import gcd
from operator import mul
from random import randrange


class PrimeFactor:
    def __init__(self):
        pass

    def is_prime(self, N):
        """ミラーラビン"""
        v = [2, 7, 61] if N < 4_759_123_141 else \
            [2, 3, 5, 7, 11, 13, 17] if N < 341_550_071_728_321 else \
            [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]
        if N < 2:
            return False
        if N in v:
            return True
        d = N - 1
        s = 0
        while d % 2 == 0:
            d //= 2
            s += 1

        for a in v:
            if pow(a, d, N) != 1:
                ok = True
                for r in range(s):
                    if pow(a, d * 1 << r, N) == N - 1:
                        ok = 0
                        break
                if ok:
                    return False
        return True

    def f(self, x, n, c):
        return (x * x + c) % n

    def get_factor(self, n):
        c = randrange(1, n)
        if n % 2 == 0:
            return 2
        if self.is_prime(n):
            return n
        x = randrange(1, n)
        y, d = x, 1

        while d == 1:
            x = self.f(x, n, c)
            y = self.f(self.f(y, n, c), n, c)
            d = gcd(abs(x - y), n)
        if d == n:
            return self.get_factor(n)
        return self.get_factor(d)

    def factorization(self, N):
        """素因数分解"""
        if N == 1:
            return [1]
        arr = []
        while N > 1:
            k = self.get_factor(N)
            cnt = 0
            while N % k == 0:
                cnt += 1
                N //= k
                arr.append(k)
        return arr

    def divisors(self, N):
        """約数列挙"""
        if N == 1:
            return [1]
        c = Counter(self.factorization(N))
        mul_list = []
        for i in c:
            tmp = [1] * (c[i] + 1)
            for j in range(c[i]):
                tmp[j + 1] = tmp[j] * i
            mul_list.append(tmp)
        res = [reduce(mul, v) for v in product(*mul_list)]
        return res

    def count_divisors(self, N):
        """約数の個数"""
        if N == 1:
            return 1
        res = 1
        for i in Counter(self.factorization(N)).values():
            res *= i + 1
        return res


n = int(input())
p = PrimeFactor()
a = p.divisors(n)[1:]
ans = 0
for i in a:
    k = n
    while k % i == 0:
        k //= i
    if k % i == 1:
        ans += 1
ans += p.count_divisors(n - 1) - 1
print(ans)


Measured memory_bytes: 83260
def is_reachable(dept, dest):
    distance = abs(dest[1] - dept[1]) + abs(dest[2] - dept[2])
    time = dest[0] - dept[0]
    if (time - distance >= 0) and ((time - distance) % 2 == 0):
        return True
    else:
        return False


N = int(input())
itin = [(0, 0, 0)]
itin_append = itin.append
for n in range(N):
    itin_append(tuple(map(int, input().split())))

for n in range(N):
    if is_reachable(itin[n], itin[n + 1]):
        continue
    else:
        print('No')
        break
else:
    print('Yes')


Measured memory_bytes: 61656
S = input()

ans = len(S)
for i, s in enumerate(S[::-1]):
    #print(i, s, S[:-(i+1)])
    m, n = 0, 0
    for j, c in enumerate(S[:-(i+1)][::-1]):
        if c == s:
            n = max(m, n)
            m = 0
        else:
            m += 1
    n = max(m, n)
    ans = min(ans, max(i, n))
    #print(m, n, i, ans)
print(ans)

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

N,M = map(int,input().split())
shoplist = []
for i in range(N):
  A,B = map(int,input().split())
  shoplist.append([A,B])

shoplist.sort(key=lambda x: x[0])
rtn=0
for elm in shoplist:
  if M==0:
    break
  if M >= elm[1]:
    rtn+=elm[0]*elm[1]
    M-=elm[1]
  else:
    rtn+=elm[0]*M
    M=0
print(rtn)

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

int N, A[300000];

bool check(int K){
    stack<pair<int, int>> st;
    for(int i=0; i<N-1; i++){
        if(A[i] >= A[i+1]){
            while(st.size() && st.top().first > A[i+1]) st.pop();
            if(st.size() && st.top().first == A[i+1]){
                st.top().second++;
            }else{
                st.push({A[i+1], 1});
            }
            while(st.top().second == K){
                int d = st.top().first;
                if(d == 1) return false;
                st.pop();
                if(st.size() && st.top().first == d-1){
                    st.top().second++;
                }else{
                    st.push({d-1, 1});
                }
            }
        }
    }
    return true;
}

int main(){
    cin >> N;
    for(int i=0; i<N; i++) cin >> A[i];

    bool incr = true;
    for(int i=0; i<N-1; i++) if(A[i] >= A[i+1]) incr = false;
    if(incr){
        cout << 1 << endl;
        return 0;
    }

    int ng = 1, ok = N;
    while(ok-ng>1){
        int mid = (ng+ok)/2;
        (check(mid) ? ok : ng) = mid;
    }
    cout << ok << endl;
    return 0;
}

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

#define int long long

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

int N, C, K;
int T[100000];

signed main() {
    cin >> N >> C >> K;
    for (int i = 0; i < N; i++) {
        cin >> T[i];
    }
    sort(T, T + N);
    int ans = 1;
    int ninzuu = 0, saisyo = 0;
    for (int i = 0; i < N - 1; i++) {
        if (ninzuu == 0) {
            saisyo = T[i];
        }
        ninzuu++;
        if (ninzuu == C || T[i + 1] - saisyo > K) {
            ninzuu = 0;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using vi = vector<int>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    ll n,k;
    cin >> n >> k;
    vector<ll> v(100100,0);
    rep(i,n){
        int a,b;
        cin >> a >> b;
        v[a] += b;
    }
    ll cnt = 0;
    rep(i,100100){
        cnt += v[i];
        if(cnt >= k){
            cout << i << endl;
            break;
        }
    }
}

Measured memory_bytes: 1024
;; -*- coding:utf-8 -*-

(defparameter *file-path* *load-pathname*)

(defun clip-to-string ()
  (with-output-to-string (out)
    (sb-ext:run-program "C:/msys64/usr/bin/cat.exe" '("/dev/clipboard") :output out)))

(defun test ()
  (with-input-from-string (*standard-input* (clip-to-string))
    (load file-path)))


(let* ((n (read))
       (arr (make-array (list 2 n) :element-type 'fixnum :initial-element 0)))
  (dotimes (i n)
    (setf (aref arr 0 i) (read)))
  (dotimes (i n)
    (setf (aref arr 1 i) (read)))
  (princ
   (apply #'max
	  (loop for turning-point from 0 below n collect
	       (+ (loop for idx1 from 0 to turning-point
		     sum (aref arr 0 idx1))
		  (loop for idx2 from turning-point below n
		     sum (aref arr 1 idx2))))))
  (fresh-line))
  


Measured memory_bytes: 19552
#include <stdio.h>
#include <math.h>
#define TRUE 1
#define FALSE 0

int isPrime( int );
int main()
{
  int i, n, c = 0;
  int E[10000];
  
  scanf("%d", &n);
  for(i = 0; i < n; i++)
    {
      scanf("%d", &E[i]);
      if(isPrime( E[i] ) == TRUE) c++;
    }
  printf("%d\n", c);
  return 0;
}

int isPrime( int x )
{
  int i;
  
  if(x == 2) return TRUE;
  else if(x < 2 || x%2 == 0) return FALSE;
  else
    {
      i = 3;
      while( i <= sqrt(x) )
	{
	  if(x%i == 0) return FALSE;
	  i+=2;
	}
      return TRUE;
    }
}

Measured memory_bytes: 628
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t,n,m,i,j,k,x,y,u=0,h;
    cin>>x;
    for (int i = 0; i < 1000; i++) {
        for (int j = -1000; j < 1000; j++) {
            if (x == (pow(i, 5) - pow(j, 5))) {
                cout << i << " " << j;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 4084
N = int(input())
A = [int(input()) for _ in range(N)]

sum_A = sum(A)
MOD = 998244353

dp1 = [0] * (sum_A + 1)
dp2 = [0] * (sum_A + 1)
dp1[0] = dp2[0] = 1

for a in A:
    dp1_ = [0] * (sum_A + 1)
    dp2_ = [0] * (sum_A + 1)
    for i in range(sum_A + 1):
        # R に塗った場合
        if i + a <= sum_A:
            dp1_[i + a] = (dp1_[i + a] + dp1[i]) % MOD
            dp2_[i + a] = (dp2_[i + a] + dp2[i]) % MOD
        # G, B に塗った場合
        dp1_[i] = (dp1_[i] + dp1[i] * 2) % MOD
        dp2_[i] = (dp2_[i] + dp2[i]) % MOD
    dp1 = dp1_
    dp2 = dp2_

ans = pow(3, N, MOD)
for i in range(sum_A + 1):
    if i * 2 >= sum_A:
        ans = (ans - dp1[i] * 3 + MOD * 3) % MOD
    if i * 2 == sum_A:
        ans = (ans + dp2[i] * 3) % MOD
print(ans)


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

int main(){
  int n, k; cin >> n >> k;
  string s; cin >> s;

  vector<int> nums;
  int cnt = 0, c = 1;
  for(int i=0; i<n; ++i){
    if(s[i] == (char)(c + '0')) ++cnt;
    else{
      nums.push_back(cnt);
      cnt = 1;
      c = 1 - c;
    }
  }
  if(cnt != 0) nums.push_back(cnt);
  if(nums.size() % 2 == 0) nums.push_back(0);

  int ans = 0, l = 0, r = 0, sum = 0;

  for(int i=0; i<nums.size(); i+=2){
    int nextLeft = i;
    int nextRight = min(i+2*k+1, (int)nums.size());

    while(l < nextLeft){
      sum -= nums[l++];
    }

    while(r < nextRight){
      sum += nums[r++];
    }

    ans = max(ans, sum);
  }

  cout << ans << endl;
}


Measured memory_bytes: 1020
N=int(input())
if 2<=N<=3:
    print("2")
elif 4<=N<=7:
    print("4")
elif 8<=N<=15:
    print("8")
elif 16<=N<=31:
    print("16")
elif 32<=N<=63:
    print("32")
elif 64<=N<=100:
    print("64")
elif N==1:
    print("1")

Measured memory_bytes: 38384
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    // Your code here!
    long long int L[100];
    int N;
    scanf("%d",&N);
    L[0]=2;
    L[1]=1;
    for(int i=2;i<87;i++){
        L[i]=L[i-1]+L[i-2];
    }
    cout<<L[N]<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << x << endl;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int main(){
    int n;
    cin >> n;
    vector<ll>a(n);
    rep(i,n){
        cin >> a[i];
    }
    vector<int>b;
    ll A=0,B=0;
    rep(i,n){
        if(i%2==0){
            if(a[i]>0){
                A+=a[i];
            }
        }else{
            if(a[i]>0){
                B+=a[i];
            }
        }
    }
    if(A==0 and B==0){
        int hoge = (int)(max_element(a.begin(),a.end())-a.begin());
        cout << a[hoge] << endl;
        cout << n-1 << endl;
        rep(i,hoge)cout << 1 << endl;
        rep(i,n-1-hoge){
            cout << n-hoge-i << endl;
        }
        return 0;
    }else{
        if(A>B){
            //show(A);
            rep(i,n){
                if(i%2==0 and a[i]>0){
                    b.push_back(i+1);
                }
            }
        }
        else {
            //show(B);
            rep(i,n){
                if(i%2==1 and a[i]>0){
                    b.push_back(i+1);
                }
            }
        }
        cout << max(A,B) << endl;
        vector<int>ans;
        rep(i,n-b[b.size()-1]){
            ans.push_back(n-i);
        }
        rep(i,*b.begin()-1){
            ans.push_back(1);
        }
        int k = 0;
        while(k+1 < b.size()){
            rep(i,(b[k+1]-b[k])/2-1){
                ans.push_back(3);
            }
            ans.push_back(2);
            k++;
        }
        cout << ans.size() << endl;
        rep(i,ans.size()){
            cout << ans[i] << endl;
        }
    }
}

Measured memory_bytes: 256
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


n = II()
t, a = LI()
H = LI()

ans = 1
ans_t = INF
for i in range(n):
    temp = abs(a - (t - H[i] * 0.006))
    if temp < ans_t:
        ans_t = temp
        ans = i + 1

print(ans)


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


void solve(long long X){
    if(X == 1){
        cout << 1 << endl;
        return;
    }
    ll ans = 2;
    for(ll i=2; i*i<=X; i++){
        ll b = i;
        while(b <= X){
            if(b>i)
                ans = max(ans, b);
            b *= i;
        }
    }
    cout << ans << endl;
}

int main(){
    long long X;
    scanf("%lld",&X);
    solve(X);
    return 0;
}


Measured memory_bytes: 256
s = input().split()
L = int(s[0])
R = int(s[1])

MIN = 2020
flag = 0

for i in range(L,R+1):
    for j in range(i+1,R+1):
        mod = i*j % 2019
        MIN = min(MIN,mod%2019)
        if MIN == 0:
            flag = 1
            break
    if flag == 1:
        break

if R == 0 or L == 0:
    print(0)
elif R - L == 1:
     print((R*L)%2019)
else:
    print(MIN)

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>

using namespace std;

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

ll GCD(ll a ,ll b){
	return b > 0 ? GCD(b,a%b) : a;
}

ll LCM(ll a ,ll b){
	return a / GCD(a,b) * b;
}
int main(){
	int a[3],m[3];
	while(~scanf("%d %d %d %d %d %d",a,m,a+1,m+1,a+2,m+2)){
		int p[3]={1,1,1};
		int c[3]={0,0,0};
		bool end=true;
		for(int i=0;i<3;i++){
			if(a[i]!=0 || m[i]!=0){
				end = false;
				break;
			}
		}

		if(end) break;

		for(int i=0;i<3;i++){
			do{
				p[i] = a[i]*p[i]%m[i];
				c[i]++;
			}while(p[i] != 1);
		}
		cout << LCM(LCM(c[0],c[1]),c[2]) << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define loop(i,n) for(int i = 0;i < (n);i++)
#define all(A) A.begin(),A.end()
#define pb push_back
#define mp make_pair
#define sz(A) ((int)A.size())
typedef std::vector<int> vi;
typedef std::pair<int,int> pi;
typedef std::vector<pi> vp;
typedef long long ll;
#define popcnt(x) __builtin_popcount(x)
#define LSOne(x) ((x) & (-(x)))
#define print(A,t) cerr << #A << ": "; copy(all(A),ostream_iterator<t>(cerr," " )); cerr << endl
#define prArr(A,n,t)  cerr << #A << ": "; copy(A,A + n,ostream_iterator<t>(cerr," " )); cerr << endl
#define PRESTDIO() cin.tie(0),cerr.tie(0),ios_base::sync_with_stdio(0)
#define what_is(x) cerr << #x << " is " << x << endl
#define bit_lg(x) (assert(x > 0),__builtin_ffsll(x) - 1)
const double PI = acos(-1);
template<class A,class B>
std::ostream& operator << (std::ostream& st,const std::pair<A,B> p) {
	st << "(" << p.first << ", " << p.second << ")";
	return st;
}
#define tc() int T; scanf("%d",&T); for(int t = 1;t <= T;t++)
using namespace std;

const int MAXN = 100*1000 + 10;
int A[MAXN],n;
vi E[MAXN];
int fr[MAXN],to[MAXN],W[MAXN];
int deg[MAXN],S[MAXN];


void dfs(int u,int p,int e) {
	int ctr = 0;
	for(int e : E[u]) {
		int v = fr[e] + to[e] - u;
		if(v == p) continue;
		dfs(v,u,e);
		ctr++;
		S[u] += W[e];
	}
	if(!ctr) W[e] = A[u];
	else W[e] = 2*A[u] - S[u];
//	if(p) cerr << p << " " << u << " " << W[e] << endl;
}
bool check(){
	for(int u = 1;u <= n;u++) {
		ll s = 0;
		int w = 0;
		for(int e : E[u]) {
			if(W[e] < 0) return 0;
			s += W[e];
			w = max(w,W[e]);
		}
		if(sz(E[u]) == 1) {
			if(w != A[u]) return 0;
			continue;
		}
//		cerr << u << " " << A[u] << " " << s << " " << w << endl;
		if(s != 2*A[u]) return 0;
		if(w > A[u]) return 0;
	}
	return 1;
}

int main(){
#ifdef HOME
	freopen("in.in", "r", stdin);
#endif
	scanf("%d",&n);
	for(int u = 1;u <= n;u++) scanf("%d",A + u);
	loop(e,n-1) {
		scanf("%d %d",fr + e,to + e);
		E[fr[e]].push_back(e);
		E[to[e]].push_back(e);
	}
	dfs(1,0,n);
	puts(check() ? "YES" : "NO");
	return 0;
}


Measured memory_bytes: 14336
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <string>
#include <algorithm>



using namespace std;


int main (void)
{
    int a[100],K = 0;
    char b[100];

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

    for (int i = 0; i < 100; i++)
    {
        cin >> b[i];
        if (b[i] == '=')
        {
            K = a[i - 1];
            break;
        }
        cin >> a[i];

        if (b[i] == '+')
        {
            a[i] = a[i - 1] + a[i];
        }
        else if (b[i] == '-')
        {
            a[i] = a[i - 1] - a[i];
        }
        else if (b[i] == '*')
        {
            a[i] = a[i - 1] * a[i];
        }
        else if (b[i] == '/')
        {
            a[i] = a[i - 1] / a[i];
        }
        
    }

    cout << K << endl;
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define int ll
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int a,b,x,y; cin>>a>>b>>x>>y;
	cout<<(a*b/2.0)<<" ";
	if(x*2==a && y*2==b) cout<<"1\n";
	else cout<<"0\n";
	return 0;
}















Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mp(a,b) make_pair(a,b)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
const int MOD=1000000007;
const double pi = 3.141592653589793;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int h,w,k;
    cin>>h>>w>>k;
    vector<vector<char>> c(h,vector<char> (w,'.'));
    vector<vector<char>> tmp(h,vector<char> (w,'.'));
    rep(i,h){
        rep(j,w){
            cin>>c[i][j];
        }
    }
    int ans = 0;
    //bit全探索　それぞれの列に対して派閥構成可能だったら1の数
    for(int rbit=0; rbit< (1<<h);rbit++){
        bitset<6> gyo(rbit);
        //行について選ぶか選ばないか
        for(int cbit=0;cbit< (1<<w);cbit++){
            tmp = c;
            bitset<6> retu(cbit);
            //cout<<gyo<<" "<<retu<<endl;
            for(int i=0;i<h;i++){
                if(gyo.test(i)){//i行目を選ぶ->i行目を塗る
                    rep(ret,w){
                        tmp[i][ret] = 'r';//赤く塗る
                    }
                }
            }
            for(int j=0;j<w;j++){
                if(retu.test(j)){//j列目を選ぶ->j列目を赤く塗る
                    rep(g,h){
                        tmp[g][j]='r';
                    }
                }
            }
                //黒がk個か確認
        int cnt=0;
        rep(i,h){
            rep(j,w){
                if(tmp[i][j]=='#') {
                    cnt++;
                }
            }
        }
        if(cnt==k){
            /*
            cout<<"====="<<endl;
            cout<<gyo<<" "<<retu<<endl;
            rep(i,h){
                rep(j,w){
                    cout<<tmp[i][j]<<" ";
                }
                cout<<endl;
            }
            */
            ans++;
        }
        }
    }
    cout<<ans<<endl;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

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)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define VIN(v) for(auto&elem_: (v) )cin>>elem_
#define VOUT(v, sep) for(_loop_int idx=0; idx<(_loop_int)v.size(); idx++) {cout<<v[idx]; if(idx<v.size()-1) cout<<sep;} cout<<endl

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(debugidx,v.size())cout<<" "<<v[debugidx];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(debugidx,n)cout<<" "<<v[debugidx];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
const int IINF = numeric_limits<int>::max()/2-1;
const ll LINF = numeric_limits<ll>::max()/2-1;
#define FIX(a) ((a)%MOD+MOD)%MOD

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int n;
    cin>>n;
    string ans = (n==7||n==5||n==3)?"YES":"NO";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
let a = Array.make 10 0 in
for i = 0 to 9 do
	Scanf.scanf "%d\n" (fun x -> a.(i) <- x)
done;
Array.fast_sort (fun x y -> compare y x) a;
for i = 0 to 2 do
	Printf.printf "%d\n" a.(i)
done;

Measured memory_bytes: 2368
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<cmath>
#include<ctime>
#include<queue>
#include<map>
#include<vector>
#define rint register int
#define debug(x) cerr<<#x<<"="<<x<<endl
#define fgx cerr<<"-------------"<<endl
typedef long long ll;
using namespace std;
ll a[1000],f[1000][2];
int main()	
{	int n; cin>>n;
	for(rint i=1;i<=n;i++) cin>>a[i];
	f[0][0]=1;
	for(rint i=1;i<=n;i++)
	{	if(a[i]&1)
		{	f[i][0]=f[i-1][0];
			f[i][1]=2*f[i-1][0]+3*f[i-1][1];
		}
		else
		{	f[i][0]=2*f[i-1][0];
			f[i][1]=f[i-1][0]+3*f[i-1][1];
		}
	}
	cout<<f[n][1]<<endl;
 	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;

    int right = n;
    int left = 1;

    for (int i = 0; i < m; i++)
    {
        int l, r;
        cin >> l >> r;
        left = max(left, l);
        right = min(right, r);
    }
    cout << max(0, (right + 1 - left)) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int N,A[27]={};
char S[51]={};
int main(){
	scanf("%d",&N);
	memset(A,10,sizeof(A));
	for(int i=1;i<=N;i++){
		scanf("%s",S);
		int len=strlen(S);
		int B[27]={};
		for(int j=0;j<len;j++)
		 ++B[S[j]-'a'];
		for(int j=0;j<26;j++) A[j]=min(A[j],B[j]);
	}
	for(int i=0;i<26;i++){
		for(int j=1;j<=A[i];j++)
		 printf("%c",char('a'+i));
	}
	puts("");
	return 0;
}

Measured memory_bytes: 256
let main () =
  let n, y = Scanf.sscanf (read_line ()) "%d %d" (fun a b -> (a, b)) in
  let numOf10000 = ref (-1) in
  let numOf5000 = ref (-1) in
  let numOf1000 = ref (-1) in
  (
    for i = 0 to n do
      for j = 0 to n - i do
        let k = n - i - j in
        let sum = 10000 * i + 5000 * j + 1000 * k in
        if sum = y
        then
          (
            numOf10000 := i;
            numOf5000 := j;
            numOf1000 := k
          )
      done
    done;
    Printf.printf "%d %d %d" !numOf10000 !numOf5000 !numOf1000;
    print_newline ()
  )

let _ = main ()


Measured memory_bytes: 3852
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,k,cnt=0;
	scanf("%d%d%d",&n,&m,&k);
	for (int i=max(n,m);i>=1;i--)
	{
		if (n%i==0 && m%i==0) {
			cnt++;
			if (cnt==k) {
				printf("%d\n",i);
				return 0;
			}
		} 
	}
}

Measured memory_bytes: 256
/*    Mohammed Sami Khan
                       মোহাম্মদ সামী খান
*/
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define mp(a,b) make_pair(a,b)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;
typedef unsigned long long ull;

bool sortbysecc(const pair<int,int> &a, const pair<int,int> &b){
    return (a.second < b.second);
}

int main()
{
    fastio;
    ll t, n, m, x=0, y=0, p, q, r, i, j, d, f=0;
    cin>>n;
    ll a[n];
    for(i=0;i<n;i++){
        cin>>a[i];
        if(a[i]%2) x++;
    }
    if(x%2) cout<<"NO";
    else cout<<"YES";
}


Measured memory_bytes: 4404
using namespace std;
#include<bits/stdc++.h>
#define int long long
#define pb push_back 
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ff first
#define ss second
#define repa(i,a,b) for (int i=a; i<=b; i++)
#define repd(i,b,a) for (int i=b; i>=a; i--)
#define endl "\n"
//debugging
#define debug1(a) cout<<#a<<" = "<<(a)<<endl;
#define debug2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define debug3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;
#define debug4(a,b,c,d) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<", "<<#d<<" = "<<(d)<<endl;

const int N = 1e+6+5;
int BIG = 1e+18+3;
int mod = 1e+9+7;

signed main()
{
    IOS;
    int n,w; cin>>n>>w;

    vector< pair<int,int> >v(n+1);

    repa(i,1,n)
        cin>>v[i].ff>>v[i].ss;

    sort(v.begin()+1,v.end());

    int dp[n+1][w+1];

    repa(i,0,n)
        repa(j,0,w)
            dp[i][j] = 0;

    repa(i,1,n)
    {
        repa(j,1,w)
        {
            int bufValue = -v[i].ss;

            if (j-v[i].ff>=0)
                bufValue = dp[i-1][j-v[i].ff]; 

            dp[i][j] = max( dp[i-1][j], bufValue + v[i].ss );
        }
    }

    cout<< dp[n][w] <<endl;
}

Measured memory_bytes: 79232
N=int(input())
g=list(map(int,input().split()))
a=0
for i in range(N):
    a = a + g[i]
b=a/2
before=10000
c=0
for i in range(N):
    c= c+g[i]
    after=abs(c-b)
    if before>after:
        before=after
        f=c
    else:
        break
d=a-f
e=abs(d-f)
print(e)

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

int main() {
    string st; cin >> st;
    vector<int> a(4);
    for (int i = 0; i < 4; i++) {
        a[i] = st[i] - '0';
    }
    
    if (a[0]+a[1]+a[2]+a[3] == 7) cout << a[0] << "+" << a[1] << "+" << a[2] << "+" << a[3] << "=7" << endl;
    else if (a[0]+a[1]+a[2]-a[3] == 7) cout << a[0] << "+" << a[1] << "+" << a[2] << "-" << a[3] << "=7" << endl;
    else if (a[0]+a[1]-a[2]+a[3] == 7) cout << a[0] << "+" << a[1] << "-" << a[2] << "+" << a[3] << "=7" << endl;
    else if (a[0]+a[1]-a[2]-a[3] == 7) cout << a[0] << "+" << a[1] << "-" << a[2] << "-" << a[3] << "=7" << endl;
    else if (a[0]-a[1]+a[2]+a[3] == 7) cout << a[0] << "-" << a[1] << "+" << a[2] << "+" << a[3] << "=7" << endl;
    else if (a[0]-a[1]+a[2]-a[3] == 7) cout << a[0] << "-" << a[1] << "+" << a[2] << "-" << a[3] << "=7" << endl;
    else if (a[0]-a[1]-a[2]+a[3] == 7) cout << a[0] << "-" << a[1] << "-" << a[2] << "+" << a[3] << "=7" << endl;
    else cout << a[0] << "-" << a[1] << "-" << a[2] << "-" << a[3] << "=7" << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<eps)
string s;
int m;
set<string> ans;
int main()
{
	scanf("%d",&m);
	for(int i=0;i<m;i++)
	{
		cin >> s;
		ans.clear();
		for(int j=1;j<s.size();j++)
		{
			string l,r,revl,revr;
			l=s.substr(0,j);
			r=s.substr(j);
			revl = l;
			revr = r;
			reverse(revl.begin(),revl.end());
			reverse(revr.begin(),revr.end());
			ans.insert(l+r);
			ans.insert(l+revr);
			ans.insert(r+revl);
			ans.insert(revl+revr);
			ans.insert(r+l);
			ans.insert(revr+l);
			ans.insert(revl+r);
			ans.insert(revr+revl);
		}
		printf("%d\n",(int)ans.size());
	}
	return 0;
}

Measured memory_bytes: 1324
#include<stdio.h>
 int main(void)
 {
     int A,B,C,D;

     scanf("%d%d%d%d",&A,&B,&C,&D);

     if(A*B>C*D) printf("%d\n",A*B);
     else printf("%d\n",C*D);

     return 0;
 }



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

int main(){
	double h;
	double max, min;
	cin >> h;
	max = min = h;
	while(cin >> h){
		if(max < h){
			max = h;
		}else if(min > h){
			min = h;
		}
	}
	cout << max-min << endl;
	return 0;
}

Measured memory_bytes: 0