akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a)  (a).begin(),(a).end()
const ll INF = 1e18+18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
static const double pi = 3.141592653589793;



int main(){
    ll N;
    cin>>N;
    vector<ll> X(N), Y(N);
    rep(i, N){
        ll j;
        cin>>j;
        X[i]=j;
        Y[i]=j;
    }
    sort(ALL(Y));
    ll A=Y[N/2-1];
    ll B=Y[N/2];
    rep(i, N){
        if(X[i]==A){
            cout<<B<<endl;
        }
        else if(X[i]==B){
            cout<<A<<endl;
        }
        else{
            if(X[i]>A){
                cout<<A<<endl;

            }
            else{
                cout<<B<<endl;
            }
        }
    }
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define N 1000005
using namespace std;

int n, k, gg, a[N];

int gcd(int x, int y){
	if(y == 0)
		return x;
	return gcd(y, x%y);
}

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	scanf("%d %d",&n ,&k);
	for(int i = 1; i <= n; i++){
		scanf("%d",a + i);
		gg = gcd(gg, a[i]);
	}
	for(int i = 1; i <= n; i++){
		if(a[i] >= k and (a[i] - k)%gg == 0 ){
			puts("POSSIBLE");
			return 0;
		}
	}
	puts("IMPOSSIBLE");
	return 0;
}

Measured memory_bytes: 640
#include <utility>
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#include <climits>
#include <iomanip>
#define REP(i,n) for(int i=0;i<n;i++)
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
using namespace std;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int inf = 10000000;

int main() {
	cin.tie(0);
  ios::sync_with_stdio(false);
  double n, m, d;
  cin >> n >> m >> d;
  double prob = 0.0;
  if (d == 0){
    prob = (n-d)*(m-1)/n/n;
  }else{
    prob = (n-d)*(m-1)*2.0/n/n;
  }
  cout << setprecision(12) << prob << endl;
  return 0;
}

Measured memory_bytes: 764
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

void drop(string s) {
    printf("%s\n", s.c_str());
    exit(0);
}

int main() {
    int N, M; scanf("%d%d", &N, &M);
    if(M % 2) drop("-1");

    map< pair<int, int>, int > E2N;
    vector<int> group(M), visited(N), deg(N);
    vector< pair<int, int> > ans(M);
    vector< vector<int> > G(N);
    for(int i=0; i<M; i++) {
        int u, v; scanf("%d%d", &u, &v);
        u--; v--;
        G[u].emplace_back(v);
        G[v].emplace_back(u);
        E2N[ make_pair(u, v) ] = i;
        E2N[ make_pair(v, u) ] = i;
    }

    auto dfs1 = [&](auto&& self, int cur, int par) -> void {
        visited[cur] = true;
        for(auto to : G[cur]) {
            if(to == par) continue;
            int k = E2N[ make_pair(cur, to) ];
            if(visited[to]) {
                if(group[k]) continue;
                group[k] = 1;
                deg[cur]++;
                ans[k] = make_pair(cur, to);
            }
            else {
                group[k] = 0;
                self(self, to, cur);
            }
        }
    };

    auto dfs2 = [&](auto&& self, int cur, int par) -> void {
        for(auto to : G[cur]) {
            if(to == par) continue;
            int k = E2N[ make_pair(cur, to) ];
            if(group[k]) continue;
            self(self, to, cur);
            if(deg[to] % 2) {
                deg[to]++;
                ans[k] = make_pair(to, cur);
            }
            else {
                deg[cur]++;
                ans[k] = make_pair(cur, to);
            }
        }
    };

    dfs1(dfs1, 0, -1);
    dfs2(dfs2, 0, -1);
    for(int i=0; i<M; i++) printf("%d %d\n", ans[i].first + 1, ans[i].second + 1);
    return 0;
}


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

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m;
    cin >> n >> m;
    
    set<int> ok;
    map<int, int> cnt;
    int ans  =0;
    for (int i = 0; i < m; i++){
        int p;
        string s;
        cin >> p >> s;
        if(ok.count(p))continue;
        if(s == "AC") ok.insert(p);
        else cnt[p]++;
    }
    cout << ok.size();
    for (auto i : ok) {
        if(cnt.count(i)){
            ans += cnt[i];
        }
    }
    cout << ' '<< ans << "\n";
    return 0;
}


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

#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FILL(x) memset(x,0,sizeof(x))


using namespace std;

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

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

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


  int ans = 0;
  if(N>0)
    ans += N*(N-1)/2;
  if(M>0)
    ans+=M*(M-1)/2;
  cout << ans << endl;


  return 0;
}


//cout << setprecision(13);
//next_permutation();
//__gcd();
//reverse();
//set ,tuple ,pair;
//bitset
//vector.find
//vector.count



Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
   int n, m, x, a[100], i, r=0, l=0;

   scanf("%d%d%d",&n,&m,&x);
   for(i=0;i<m;i++)
      scanf("%d",&a[i]);

   i=0;
   while((a[i]<x)&&(i<m))
      i++;

   if(m<2*i)
      printf("%d\n",m-i);
   else
      printf("%d\n",i);
   return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


class union_find {
    private:
        vector<int> par;
        vector<int> ran;
        vector<ll> size;
    public:
        union_find(int n);
        int find(int x);
        void unite(int x, int y);
        bool same(int x, int y);
        ll show_size(int x);
};

union_find::union_find(int n){
    par.resize(n);
    ran.resize(n);
    size.resize(n);
    rep(i,n) par[i] = i;
    rep(i,n) ran[i] = 0;
    rep(i,n) size[i] = 1;
};

int union_find::find(int x) {
    if(par[x] == x) return x;
    else return par[x] = find(par[x]);
};

void union_find::unite(int x, int y) {
    x = find(x);
    y = find(y);
    if(x == y) return;
    ll t = show_size(x)+show_size(y);
    size[x] = size[y] = t;
    if(ran[x] < ran[y]){
        par[x] = y;
        //size[y] += size[x];
    }
    else{
        par[y] = x;
        //size[x] += size[y];
        if(ran[x] == ran[y]) ran[x]++;
    }
};

ll union_find::show_size(int x) {
    if(par[x] == x) return size[x];
    return show_size(par[x] = find(par[x]));
}

bool union_find::same(int x, int y) {
    return (find(x) == find(y));
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m, k;
	cin >> n >> m >> k;
	union_find uf(n);
	vector<set<int>> fri(n), blo(n);
	int a, b;
	rep(i,m){
		cin >> a >> b;
		a--; b--;
		fri[a].insert(b);
		fri[b].insert(a);
		uf.unite(a, b);
	}
	rep(i,k){
		cin >> a >> b;
		a--; b--;
		blo[a].insert(b);
		blo[b].insert(a);
	}
	rep(i,n){
		int ans = uf.show_size(i);
		for(auto p : fri[i]){
			if(uf.same(i, p)) ans--;
		}
		for(auto p : blo[i]){
			if(uf.same(i, p)) ans--;
		}
		ans--;
		cout << ans;
		if(i < n-1) cout << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 30592
use std::io::prelude::*;

fn input<T>() -> T
    where T: std::str::FromStr {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let v = (0..5).map(|_| input()).collect::<Vec<usize>>();
    let d = (n + v.iter().min().unwrap() - 1) / v.iter().min().unwrap() - 1 + 5;
    println!("{}", d);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long ;
int main(){
    int n;
    cin >> n;
    bool ok=false;
    vector<ll> a(n);
    vector<ll> b(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];

    ll asum=0,bsum=0;
    rep(i,n) asum += a[i];
    rep(i,n) bsum += b[i];
    if(asum >= bsum) ok=true;
    if(!ok){
        cout << -1 << endl;
        return 0;
    }
    else{
        ll cant=0,cantk=0;
        vector<ll> yoyu(n);
        rep(i,n){
            if(a[i]<b[i]){
                cant += b[i] - a[i];
                cantk++;
            }
            else{
                yoyu.push_back(a[i]-b[i]);
            }
        }
        if(cant == 0){
            cout << 0 << endl;
            return 0;
        }
        sort(yoyu.rbegin(),yoyu.rend());
        rep(i,yoyu.size()){
            cant -= yoyu[i];
            cantk++;
            if(cant<0) break;
        }
        cout << cantk << endl;
        
    }
    
}

Measured memory_bytes: 6352
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        System.out.println(A*B/Main.d(A, B));
    }
    public static long d(long A,long B) {
        if (A<B) {
            return d(B,A);
        }
        if (B==0) {
            return A;
        }
        return d(A%B,B);
    }
}


Measured memory_bytes: 35856
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using pq = priority_queue<int>;
template<class T>
using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int under = (1 << 31);
int upper = under - 1;
ll UNDER = (1LL << 63);
ll UPPER = UNDER - 1;
const int MOD = 1e9 + 7;
const long double pi = 3.141592653589793;
int main() {
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	int x = x2 - x1;
	int y = y2 - y1;
	int x3 = x2 - y;
	int y3 = y2 + x;
	int x4 = x1 - y;
	int y4 = y1 + x;
	printf("%d %d %d %d\n", x3, y3, x4, y4);
	return 0;
}

Measured memory_bytes: 256
import sys

def main():
    input = sys.stdin.readline
    H, W = map(int, input().split())

    if H % 3 == 0 or W % 3 == 0:
        return 0

    # Split into two horizontally ans one verticaly (like sample 2)
    if H % 2 == 0:
        h1, h2 = H // 2, H // 2
    else:
        h1, h2 = H // 2, H // 2 + 1

    diff_hhv = float('inf')
    for i in range(1, W):
        max_area = max(i * H, (W - i) * h2)
        min_area = min(i * H, (W - i) * h1)

        diff_hhv = min(diff_hhv, max_area - min_area)


    # Split into one horizontally and two vertically (like sample 3)
    if W % 2 == 0:
        w1, w2 = W // 2, W // 2
    else:
        w1, w2 = W // 2, W // 2 + 1

    diff_hvv = float('inf')
    for i in range(1, H):
        max_area = max(i * W, (H - i) * w2)
        min_area = min(i * W, (H - i) * w1)

        diff_hvv = min(diff_hvv, max_area - min_area)

    return min(H, W, diff_hhv, diff_hvv)


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define pb push_back
void solve(){
    ll a,b,n;
    cin>>a>>b>>n;
    if(n>b-1){
        cout<<floor((a*(b-1))/double(b));
    }
    else{
        cout<<floor((a*n)/double(b));
    }
}
int  main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t;
    //cin>>t;
	t=1;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 3764
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <algorithm>

typedef long long ll;
const ll MAX_NUM = 1e5;

int main()
{
  ll N, M;
  std::cin >> N >> M;

  std::priority_queue< ll,  std::vector< ll >, std::greater< ll > > que[MAX_NUM+1];
  
  std::vector< ll > vp(M, 0);
  std::vector< ll > vy(M, 0);
  for (ll i = 0; i < M; i++) {
    std::cin >> vp[i] >> vy[i];
    que[vp[i]].push(vy[i]);
  }

  std::map< std::pair< ll, ll >, ll > map_num;
  for (ll p = 0; p <= MAX_NUM; p++) {
    ll number = 1;
    while (!que[p].empty()) {
      const ll& y = que[p].top();
      map_num[std::make_pair(p, y)] = number;
      que[p].pop();
      number++;
    }
  }

  for (ll i = 0; i < M; i++) {
    printf("%06lld%06lld\n",vp[i], map_num[std::make_pair(vp[i], vy[i])]);
  }
  
  return 0;
}


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

int main()
{
	long long n;

	long long i;

	long long o;

	cin >> n;
	cin >> i;
	o = 1;


	if (n * 2<= i)

		o = n + (i - 2 * n) / 4 ;


	else 
		o = i / 2 ;




	cout << o << endl;






}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll long long
#define ld long double
#define MAX 1000000000
#define MOD 1000000007
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t=1;
	//cin>>t;
	for(int cc=1;cc<=t;cc++){
        //cout<<"Case #"<<cc<<": ";
        ll n,k,a=0,b=0,ans=0;
        cin>>n>>k;
        for(int i=0;i<=n;i++){
        	a+=i%MOD;
        	b+=(n-i)%MOD;
        	if(i+1>=k)
        		ans+=(b-a+1)%MOD;        	
        }
        cout<<ans%MOD<<endl;
	}
}


Measured memory_bytes: 3660
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<functional>
using namespace std;
int main() {
	int n;
	long double x1, y1, x2, y2, x3, y3, x4, y4;
	cin >> n;
	for (int z = 0; z < n; z++) {
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
		if((y2-y1)/(x2-x1)==(y4-y3)/(x4-x3)) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define For(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define sz(x) ((int)(x).size())
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef long long ll;

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

  int n,k; cin>>n>>k;
  vi h(n); rep(i,n) cin>>h[i];
  vi dp(n,INF); dp[0] = 0;
  for(int i=1;i<n;i++) {
    for(int j=i-1;j>=max(0,i-k);j--) {
      dp[i] = min(dp[i], dp[j]+abs(h[i]-h[j]));
    }
  }
  cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define deb(x) cout<<x<<"\n";
#define deB(x,y) cout<<x<<" "<<y<<"\n";
#define Deb(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n";
#define YES cout<<"YES\n";
#define Yes cout<<"Yes\n";
#define NO cout<<"NO\n";
#define No cout<<"No\n";
#define clt(x) 63-__builtin_clzll(x)
#define bct(x) __builtin_popcountll(x)
#define all(v) (v).begin(),(v).end()
#define pi pair<ll,ll>
#define vi vector<ll>
#define vpi vector<pair<ll,ll>>
#define maxq priority_queue<ll>
#define minq priority_queue<ll,vector<ll>, greater<ll>>
#define cont continue;
#define reto return 0;
#define sz size()
#define spmod 1116295198451
#define mod 1000000007
#define md 998244353 
#define N 2e5+10
//typedef tree<int,null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> //pbds;


int main()
{
  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  ll x;
  cin>>x;
  deb(1-x)
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	string s;
	cin >> s;
	for(int i=0;s[i];i++){
		if(s[i]=='A'){
			a=i;
			break;
		}
	}
	for(int i=s.size()-1;i>=0;i--){
		if(s[i]=='Z'){
			b=i;
			break;
		}
	}
	printf("%d",b-a+1);
}

Measured memory_bytes: 640
#include <bits/stdc++.h> 
using namespace std; 
int n , arr[405];
long long dp[405][405] , cum[405];
bool vis[405][406];
long long solve(int l ,int r){
	if(vis[l][r])return dp[l][r];
	vis[l][r] = true;
	if(r - l == 1)return dp[l][r] =0;
	dp[l][r] = 1e18;
	for(int i = 1; i < r - l ; i++){
		dp[l][r] = min(dp[l][r] , solve(l , l + i) + solve(l + i , r));
	}
	return dp[l][r] =dp[l][r] + cum[r] - cum[l];
}
int main(){
	cin>>n;
	for(int i = 0; i < n ; i++){
		cin>>arr[i];
		cum[i + 1] = cum[i] + arr[i];
	}
	cout<<solve(0 , n);	
	return 0;
}  


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  string s, t; cin >> s >> t;
  int res = 0;
  for (int i = 0; i < 3; ++i) {
    res += s[i] == t[i];
  }
  cout << res << '\n';
}

Measured memory_bytes: 764
#include <stdio.h>
int main(){
  int W,H,x,y,r;
  scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);
  if((x-r)<0 || (x+r)>W)printf("No\n");
  else if((y-r)<0 || (y+r)>H)printf("No\n");
  else printf("Yes\n");
  return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <sstream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
using namespace std;

typedef long long LL;

#define PrintLn(X) cout << X << endl
#define Loop(n) for(int loop_ = n; loop_; --loop_)
#define Rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define For(i, a, b) for(int i = a; i < (int)(b); ++i)

LL MOD = 1000000007;
 
LL pow_mod(LL a, LL b){
	LL res = 1;
	while(b > 0){
		if(b & 1) res = (res * a) % MOD;
		b >>= 1;
		a = (a * a) % MOD;
	}
	return res;
}

LL fact[200005];
void fact_mod(LL n){
	LL res = 1;
	Rep(i, n){
		if(i == 0){
			fact[i] = 1;
		}else{
			fact[i] = (fact[i - 1] * i) % MOD;
		}
	}
}

LL invFact[200005];
void invFact_mod(LL N){
	invFact[N] = pow_mod(fact[N], MOD-2);
	Rep(i, N){
		int n = N - 1 - i;
		invFact[n] = invFact[n+1] * (n+1) % MOD;
	}
}

LL comb_N = 1;
LL comb_num = 0;
LL comb_mod(LL n, LL r){
	if(r > n) return 0;
	return (fact[n] * invFact[r]) % MOD * invFact[n-r] % MOD;
}

int a[100005];
int b[100005];

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

	int x;
	Rep(i, N){
		cin >> a[i];
		if(b[a[i] - 1]){
			x = a[i];
		}
		b[a[i] - 1] = 1;
	}

	int y = -1;
	int z = -1;
	Rep(i, N){
		if(a[i] == x){
			if(y == -1){
				y = i;
			}else{
				z = i;
			}
		}
	}

	int num = y + (N - 1 - z);
	fact_mod(2 * N + 4);
	invFact_mod(2 * N + 2);

	Rep(i, N){
		PrintLn(((comb_mod(N, i + 1) + MOD - comb_mod(num, i)) % MOD));
	}
	return 0;
}


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

int main() {
    int N;
    cin>>N;
    vector<int>arr(N);
    for(int i=0;i<N;i++)
        cin>>arr[i];
    vector<int>ans(N,1e9+5);
    ans[0]=0;
    for(int i=0;i<N;i++){
        for(int j=i+1;j<=i+2;j++){
            if(j<N){
                ans[j]=min(ans[j],ans[i]+abs(arr[i]-arr[j]));
            }
        }
    }
    cout<<ans[N-1];
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long N, A, B, C, D, E;
  cin >> N >> A >> B >> C >> D >> E;
  cout << (N + min({A, B, C, D, E}) - 1) / min({A, B, C, D, E}) + 4;
}

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

struct graph {
	struct node {vector<int> v; int d = 0, f;};
	map<int, node> nodes;
	int count = 1;

	void read_all() {
		int n, id, k, v;
		cin >> n;
		while (n--) {
			cin >> id >> k;
			while (k--) {
				cin >> v;
				nodes[id].v.push_back(v);
			}
		}
	}
	void traverse(int id) {
		if (nodes[id].d)
			return;
		nodes[id].d = count++;
		for (int x: nodes[id].v)
			traverse(x);
		nodes[id].f = count++;
	}
	void traverse() {
		for (auto n: nodes)
			traverse(n.first);
	}
	void display_all() {
		for (auto n: nodes)
			cout << n.first << " " << n.second.d << " " << n.second.f << endl;

	}
};

int main() {
	graph g;
	g.read_all();
	g.traverse();
	g.display_all();
}



Measured memory_bytes: 3128
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fr first
#define sc second
#define pb push_back
#define maxheap priority_queue<int>
#define minheap priority_queue<int, vector<int>, greater<int> >
const int INF = 1e9+7;
const int MAXN = 5e5 + 200;
const  long double eps = 1e-16;
const long double pi = acos(-1.0);
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 1e5;
int n;
int a[MAXN];
int b[MAXN];
void solve(){
    cin >> n;

    for (int i = 1; i <= n; i++){
        int x;
        cin >> x;
        if (i % 2) a[x]++;
        else
            b[x]++;
    }
    int ans1 = 0;
    int ans2 = 0;
    int ind1 = 0;
    int ind2 = 0;
    for (int i = 1;  i <= N; i++){
        if (a[i] >= ans1){
            ans2 = ans1;
            ind2 = ind1;
            ans1 = a[i];
            ind1 = i;
        }
        else
        if (a[i] > ans2){
            ans2 = a[i];
            ind2 = i;
        }
    }
    int ns1 = 0;
    int ns2 = 0;
    int nd1 = 0;
    int nd2 = 0;
    for (int i = 1; i <= N; i++){
        if (b[i] >= ns1){
            ns2 = ns1;
            nd2 = nd1;
            ns1 = b[i];
            nd1 = i;
        }
        else
        if (b[i] > ns2){
            ns2 = b[i];
            nd2 = i;
        }
    }
    int kol = n / 2;
    if (ind1 != nd1){
        cout << kol - ans1 + kol - ns1 << endl;
        return;
    }
    int otv = 0;
    otv = min(kol - ans1 + kol - ns2, kol - ans2 + kol - ns1);
    cout << otv << endl;

}



int main() {
ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
cout.setf(ios::fixed), cout.precision(10);
 //freopen("input.in", "r", stdin);
// freopen("output.out", "w", stdout);
 int step;
 step = 1;
  for (int i = 1; i <= step; i++){
         solve();
    }
}


Measured memory_bytes: 1024
import java.util.*;
class Main{
    boolean[] pn;
    void run(){
	Scanner sc=new Scanner(System.in);
	setPN();
	while(true){
	    int a=sc.nextInt();
	    int d=sc.nextInt();
	    int n=sc.nextInt();
	    if((a|d|n)==0)break;
	    int count=0;
	    for(int i=a;;i+=d){
		if(pn[i]){
		    count++;
		    if(count==n){
			System.out.println(i);
			break;
		    }
		}
	    }
	}
    }
    void setPN(){
	pn=new boolean[1000000];
	Arrays.fill(pn,true);
	pn[0]=false;pn[1]=false;
	for(int i=0;i*i<1000000;i++){
	    if(pn[i]){
		for(int j=i+i;j<1000000;j+=i){
		    pn[j]=false;
		}
	    }
	}
    }
    public static void main(String[] args){
	new Main().run();
    }
}

Measured memory_bytes: 13000
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int D = sc.nextInt();
    if (N % (D * 2 + 1) == 0) {
      System.out.println(N / (D * 2 + 1));
    } else {  
      System.out.println(N / (D * 2 + 1) + 1);
    }
  }
}

Measured memory_bytes: 20820
#include<bits/stdc++.h>
using namespace std;
typedef long long int lld;

vector<int> word[26];
bool flg[26];
int cnt[26];

void solve(int now){
  flg[now] = false;
  for(int i=0;i<word[now].size();i++){
    if(flg[word[now][i]]) solve(word[now][i]);
  }
}

int main(){
  int n;
  while(cin >> n , n){
    for(int i=0;i<26;i++){
      word[i].clear();
    }
    memset(flg,false,sizeof(flg));
    memset(cnt,0,sizeof(cnt));
    int l,r;
    for(int i=0;i<n;i++){
      string str; cin >> str;
      l = str[0] - 'a';
      r = str[str.size()-1] - 'a';
      word[l].push_back(r);
      cnt[l]++; cnt[r]--;
      flg[l] = flg[r] = true;
    }
    solve(l);
    bool ans = true;
    for(int i=0;i<26;i++){
      if(flg[i] || cnt[i]){
	ans = false;
	break;
      }
    }
    if(ans) cout << "OK" << endl;
    else cout << "NG" << endl;
  }
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i,n) for (int i=(int)(n)-1; i>=0; --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) rep(i, x.size()) cerr << x[i] << (i == x.size() - 1 ? "\n" : " ")
#define all(x) x.begin(),x.end()
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;

//=============================
int N,M,K;
string S,T;
vector<int> A;
vector<int> B;
vector<string> v;
//=============================
void input()
{
    cin>>N;
    v.resize(N);
    rep(i,N){
        cin>>v[i];
    }
}
//=============================
void func(){}
vector<string> vs;
//=============================
void solve()
{
    for (auto x: v){
        string s = x;
        sort(s.begin(),s.end());
        vs.push_back(s);
    }

    sort(all(vs));

    //debugv(vs);

    map<string,int> mp;
    for (auto x : vs){
        mp[x]++;
    }
    int ans=0;
    
    //debug(mp.size());
    auto it = mp.begin();
    while(it != mp.end()){
            ans += ((it->second) * (it->second - 1) / 2);
        //cout<<it->first<<" " << it->second<<endl;
        it++;

    }


    // vector<int> va;

    // for (int i=1; i<N;i++){
    //     if(vs[i]==vs[i-1]){
    //         ans++;
    //     }
    // }
    cout<<ans<<endl;


}
//=============================
signed main()
{
    input();
    solve();
    return 0;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int a,b; cin >> a >> b;
    int n = b-a;
    int h = n*(n+1)/2;
    cout << h - b << endl;
    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    int a[n * 2 + 1];
    for( int i = 0; i < n * 2; ++i ) cin >> a[i];
    sort( a, a + (n * 2), greater<>() );
    int sum = 0;
    for( int i = 1; i < n * 2; i += 2 ) {
        sum += a[i];
    }

    cout << sum << endl;
    return 0;
}



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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;

int main() {
	int a, b, c, k;
	int sum = 0;
	cin >> a >> b >> c >> k;

	if (a > k) {
		cout << k << endl;
		return 0;
	}
	else {
		k -= a;
		sum += a;

		if (k >= b) {
			k -= b;
			sum -= k;
		}
		else {
			//
		}
		cout << sum << endl;
		return 0;

	}
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define forp(x,a,b) for(int x=a; x<b; x++)
#define forn(x,a,b) for(int x=a; x>b; x--)
#define SZ(a) ((int)(a).size())
#define pb push_back
#define vec(x) vector<x>
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pair<int,int>>
#define umpii unordered_map<int,int>
#define all(v) v.begin(),v.end()
#define mem(a,b) memset(a, b, sizeof a)
#define setBits(n) __builtin_popcountll(n)
#define prec(n) fixed<<setprecision(n)
#define ff first
#define ss second
#define print(x) for(auto it:x) cout<<it<<" ";
using namespace std;
typedef long long ll;

int pot(int x,int y){if(y==0){return 1;}
else{return x*pot(x,y-1);}
}

int bin(int x,int y){if((x==0 && y!=0)||(y==0 && x!=0)){return 1;}
else{return bin(x,y-1)+bin(x-1,y);}
}

void strlwr(string& s){for(int i=0;(unsigned)i<s.size();i++){if(s[i]>='A' && s[i]<='Z'){s[i]+=32;}}
}

int n;

bool go(int x, int a[]){bool k=false;
    forp(i,0,n){if(a[i]==x){k=true;}}
 return k;}

int main(){
    
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
     int x,t;
      cin>>x>>n;;
     
     int a[n];
     forp(i,0,n){cin>>a[i];}
     int i=0;
     bool f =true;
    
     while(f){
         if(!go(x-i,a)){t=x-i;f=false;} else{if(!go(x+i,a)){t=x+i;f=false;}}i++;}
     cout<<t;
     
    
    
    return 0;}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s, t;
  cin >> s >> t;
  int ans = 0;
  for(int i = 0; i < 3; i++){
    if(s[i] == t[i])
      ans++;
  }
  cout << ans << endl;
  return 0;
}

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

int A, B, H, M;

void rotate(double& x, double& y, double theta){
    double x_buf = x, y_buf = y;
    x = cos(theta)*x_buf - sin(theta)*y_buf;
    y = sin(theta)*x_buf + cos(theta)*y_buf;
}

int main(){
    cin >> A >> B >> H >> M;
    pair<double,double> ph = make_pair(0,A), pm = make_pair(0,B);
    double vh = 2*M_PI/12/60, vm = 2*M_PI/60;
    double theta_h, theta_m;
    theta_m = vm * M;
    theta_h = vh * (60*H + M);
    rotate(ph.first, ph.second, theta_h);
    rotate(pm.first, pm.second, theta_m);
    cout << setprecision(20) << sqrt(pow(ph.first-pm.first,2)+pow(ph.second-pm.second,2)) << endl;
    return 0;
}

Measured memory_bytes: 4104
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using Mat = vector<vl>;
const ll MOD = (1e+9)+7;

Mat dotMod(Mat& mx, Mat& my){
  ll n=mx.size();
  Mat ret(n, vl(n, 0));
  for(int x=0;x<n;x++){
    for(int y=0;y<n;y++){
      for(int i=0;i<n;i++)  
        ret[x][y] = (ret[x][y] + (mx[i][y] * my[x][i]) %MOD) %MOD; 
    }    
  }
  return ret;
}

Mat dotPow(ll p, Mat a){
  ll n = a.size(); p--;
  Mat x (a);
  while(p != 0){
    if(p%2 == 1){ 
      x = dotMod(x, a);
      p -= 1;
    }else{
      a = dotMod(a, a);
      p /= 2;
    }        
  }
  return x;
}

int main(){
  ll n,k;
  cin >> n >> k;
  Mat a(n, vl(n,0));
  for(int x=0;x<n;x++){
    for(int y=0;y<n;y++){
      cin >> a[x][y];
    }
  }
  a = dotPow(k, a);
  ll ans = 0;
  for(int x=0;x<n;x++){
    for(int y=0;y<n;y++){
      ans = (ans + a[x][y]) %MOD;      
    }
  }
  cout << ans << endl;
}

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

int main()
{
    vector<int> A;
    int q;
    cin >> q;
    for (int i = 0; i < q; i++)
    {
        int command;
        cin >> command;
        if (command == 2)
        {
            A.pop_back();
        }
        else
        {
            int value;
            cin >> value;
            if (command == 0)
            {
                A.push_back(value);
            }
            else
            {
                cout << A[value] << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3788
from collections import deque,defaultdict,Counter
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from bisect import bisect_left,bisect_right
from math import sqrt,gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode
import sys
sys.setrecursionlimit(10 ** 6)

INF = float('inf')

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse=False):
    data.sort(key=lambda x:x[col],reverse=revese)
    return data

def mymax(data):
    M = -1*float('inf')
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float('inf')
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def mydictvaluesort(dictionary):
    return sorted( dictionary.items(), key=lambda x:x[1] )

def mydictkeysort(dictionary):
    return sorted( dictionary.items(), key=lambda x:x[0] )

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(' ')
        elif type(ls[0])==str:
            print(' '.join(ls))
        elif type(ls[0])==int:
            print(' '.join(map(str,ls)))
        else:
            print('Output Error')
    else:
        if len(ls)==0:
            print('')
        elif type(ls[0])==str:
            print(''.join(ls))
        elif type(ls[0])==int:
            print(''.join(map(str,ls)))
        else:
            print('Output Error')

def I():
    return int(input())

def MI():
    return map(int,input().split())

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]

# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())

mod = 10**9 + 7

n,m = MI()
x = RI()

x.sort()
# print(x)
ls = []
for i in range(m-1):
    ls.append( x[i+1] - x[i] )
# print(ls)
ls.sort()
if n==1:
    pass
else:
    ls = ls[:-1*(n-1)]
ans = sum(ls)
print(ans)

Measured memory_bytes: 90296
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;

int main(){
	int number[100], solved[100];
	int cont = 0;
	int array[100];
	char tmp;
	int input;
	int arrayCont = 0;
	priority_queue<int> qu;

	while(cin >> number[cont] >> tmp >> solved[cont], number[cont] || solved[cont]){
		qu.push(solved[cont]);
		cont++;
	}


 	bool isFirst = true;
	while(!qu.empty()){
		if(isFirst){
			array[arrayCont] = qu.top();
			isFirst = false;
		}
		else {
			if(array[arrayCont-1] != qu.top()) array[arrayCont] = qu.top();
			else arrayCont--;

		}
		qu.pop();
		arrayCont++;
	}

	while(cin >> input){
		for(int i=0; i < cont; i++){
			if(number[i] == input){
				for(int j=0; j < arrayCont; j++){
					if(solved[i] == array[j]){
						cout << j+1 << endl;
					}
				}
			}
		}
	}
}

Measured memory_bytes: 1220
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <math.h>
#include <climits>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <map> 
#include <set>
#include <string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
const ll MD = 1000000007;

/* sample input

*/
ll n;
ll a[100002];
ll sum[100002] = {};
ll temps, tempe, tempsum = 0;

int main()
{

	cin >> n;
	temps = 0;
	for (ll i = 0; i < n; i++) {
		cin >> a[i];
		tempe = a[i];
		tempsum += abs(tempe - temps);
		temps = a[i];
	}
	a[n] = 0;
	tempsum += abs(a[n] - a[n - 1]);

	for (ll i = 0; i < n; i++) {
		ll s1, s2, s3;
		s1 = i - 1;
		s2 = i;
		s3 = i + 1;

		if (i == 0) {
			sum[i] = tempsum - abs(a[0]) - abs(a[1]-a[0])+abs(a[1]);
		}
		else {
			sum[i] = tempsum - abs(a[s2] - a[s1]) - abs(a[s3] - a[s2]) + abs(a[s3] - a[s1]);
		}
	}
	for (ll i = 0; i < n; i++) {
		cout << sum[i]<<endl;
	}

	return 0;
}

Measured memory_bytes: 2816
#include<stdio.h>
int main(void){
	int a,b,c;
	int i,j;
	int s[4];
	scanf("%d %d %d",&s[0],&s[1],&s[2]);
	for(i=0;i<2;i++){
		for(j=i+1;j<3;j++){
			if(s[i] >s[j]){
				s[3]=s[i];
				s[i]=s[j];
				s[j]=s[3];
			}
		}
	}
	printf("%d %d %d\n",s[0],s[1],s[2]);
	
	return 0;
}

Measured memory_bytes: 596
import collections
N = int(input())

def prime(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
ans = prime(N)
c = collections.Counter(ans)
count = 0
for i in c.keys():
  if c[i] <= 2:
    count += 1
  elif c[i] <= 5:
    count += 2
  elif c[i] <= 9:
    count += 3
  elif c[i] <= 14:
    count += 4
  elif c[i] <= 20:
    count += 5
  elif c[i] <= 27:
    count += 6
  elif c[i] <= 35:
    count += 7
  elif c[i] <= 44:
    count += 8

print(count)

Measured memory_bytes: 9452
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,N) for(int i = 0; i < N; i++)
#define INF 1 << 28

inline void chmax(int &a, int b) { a = max(a,b); }
inline void chmin(int &a, int b) { a = min(a,b); }

int main()
{
  int N, K;
  while(cin >> N >> K, N || K) {
    int large[100007] = {0};
    bool flag = false;
    int A;
    Rep(i,K) {
      cin >> A;
      if(A)large[A]++;
      else flag = true;
    }
    Rep(i,N + 1) {
      if(large[i + 1] > 0)large[i + 1] = large[i] + 1;
    }
    int val = large[N - 1];
    for(int i = N + 1; i >= 1; i--) {
      if(large[i] > 0) {
	large[i] = val;
      } else {
	val = large[i - 1];
      }
    }
    int maxv = -INF;
    for(int i = 1; i <= N + 1; i++) {
      if(large[i]) {
	chmax(maxv,large[i]);
      } else if(flag) {
	chmax(maxv,1 + large[i - 1] + large[i + 1]);
      } else {
	chmax(maxv,0);
      }
    }
    cout << maxv << endl;
  }
  return 0;
}

Measured memory_bytes: 3484
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#define INF 1e9

using namespace std;

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

int main() {
    int N;
    cin >> N;
    cout << N / 3 << endl;
    return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int ans = -1;
  int a,b;
  cin >> a >> b;
  rep(i,100000){
    if((int)(i*0.08) == a && (int)(i*0.10) == b){
      ans = i;
      break;
    }
  }
  cout<<(int)ans<<endl;
  return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <iomanip>
#include <vector>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int main()
{
    int n;
    cin >> n;
    vector<int> a(n + 1);
    repi(i, n, 0) cin >> a[i + 1];
    vector<int> b(n + 1);
    for (int i = n; i >= 1; --i)
    {
        int sum = 0;
        for (int j = i + i; j <= n; j += i)
        {
            sum ^= b[j];
        }
        b[i] = sum ^ a[i];
    }
    vector<int> ans;
    for (int i = 1; i <= n; i++)
    {
        if (b[i])
            ans.push_back(i);
    }
    cout << ans.size() << endl;
    repi(i, ans.size(), 0)
    {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cassert>
using namespace std;

#define REP(i,n) for (int i = 0; i < n; i++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long ll;

vector<long long> PrimeFactorization(long long n) {
    vector<long long> res;
    long long t = n;
    for (long long i = 2; i * i <= t; ){
        if (n % i == 0) res.push_back(i), n /= i;
        else i++;
    }
    if(n != 1) res.push_back(n);
    return res;
}

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

    map < int,int > cnt;
    for (int i = 2; i <= N; i++) {
        vector < ll > p = PrimeFactorization(i);
        for (int j = 0; j < p.size(); j++) {
            cnt[p[j]]++;
        }
    }
    
    int dp[1000] = {};
    dp[1] = 1;

    for (auto itr = cnt.begin(); itr != cnt.end(); itr++) {
        for (int i = 500; i >= 0; i--) {
            for (int j = 1; j <= itr->second; j++) {
                if (i * (j + 1) < 1000) {
                    dp[i * (j + 1)] += dp[i];
                }
            }
        }
    }
    
    cout << dp[75] << endl;

    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
X = set(A)
if len(X) == 1:
    if 0 in X:
        ans = 1
    else:
        ans = 0
elif len(X) == 2:
    if 0 in X:
        Y = list(X)
        if A.count(Y[0]) * 2 == A.count(Y[1]):
            ans = 1
        else:
            ans = 0
    else:
        ans = 0
elif len(X) == 3:
    Y = list(X)
    if A.count(Y[0]) == A.count(Y[1]) == A.count(Y[2]):
        ans = 1
        for i in range(40):
            Z = list(map(lambda x: x % 2,Y))
            Y = list(map(lambda x: x // 2,Y))
            Z.sort()
            #print(Z)
            if Z != [0,1,1] and Z != [0,0,0]:
                ans = 0
                break
    else:
        ans = 0
elif len(X) >= 4:
    ans = 0
if ans == 0:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 14212
#include <bits/stdc++.h>
#include <numeric>
#define M 1000000007
#define inf 1000000000000000001
#define pb push_back
#define mp make_pair
#define forz(i,s,n) for(lli i=s;i<n;i++)
#define fore(i,n,s) for(lli i=n;i>=s;i--)

#define fast_io                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

typedef long long int lli;
//typedef pair<long long int, long long int> pll;
typedef unsigned long long int ull;
using namespace std;

lli recpow(lli x, lli n)
{
    if (n == 0)
        return 1;
    else if (n % 2 == 0) //n is even
        return recpow((x * x) % M, n / 2);
    else //n is odd
        return (x * recpow((x * x) % M, (n - 1) / 2)) % M;
}

bool sortbysec(const pair<pair<lli, lli>, lli> &a,
               const pair<pair<lli, lli>, lli> &b)
{
    if(a.second==b.second)
    return (a.first.second<b.first.second);
    else
    return (a.second > b.second);
}

bool comp(pair<lli, lli> a, pair<lli, lli> b)
{
    if(a.first==b.first)
        return a.second<b.second;
    else
        return a.first<b.first;
}

string rev(string s)
{
    string t;
    fore(i,s.length()-1,0)
    {
        t.pb(s[i]);
    }
    return t;
}

lli numfac(lli n)
{
    lli ans=0;
    while(n%2==0)
    {
        ans++;
        n/=2;
    }
    lli lim=sqrt(n)+1;
    forz(i,3,lim)
    {
        while(n%i==0)
        {
            ans++;
            n/=i;
        }
    }
    if(n>2)
    ans++;
    return ans;
}

int lo(lli n)
{
    if(n%2==0 and n%4!=0)
    return 1;
    else if(n%4==0)
    return 2;
    else  
    return 3;
}

//code begins here
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    lli n,k;
    cin>>n>>k;
    if(n<=k)
    cout<<min(n, k-n);
    else  
    {
        n=n%k;
        cout<<min(n, k-n);
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(20);

    int n,a,b;
    cin>>n>>a>>b;
    cout<<n/(a+b)*a+min(a,n%(a+b))<<endl;


}

Measured memory_bytes: 256
'''
参考
https://www.planeta.tokyo/abc-129
'''
N = int(input())
W = list(map(int, input().split()))

weight_forward = 0
weight_backward = sum(W)
ans = sum(W)

for i in range(N):
    weight_forward += W[i]
    weight_backward -= W[i]

    ans = min(ans, abs(weight_backward - weight_forward))

print(ans)


Measured memory_bytes: 3316
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>

typedef long long LL;

LL s;

int main()
{
	scanf("%lld",&s);
	if (s==(LL)1e18) {printf("1000000000 0 0 1000000000 0 0\n");return 0;}
	LL t1=sqrt(s),t2=t1+1,x1,y1,x2,y2,x3,y3;
	if (t1*t1>s) t2=t1-1,std::swap(t1,t2);
	if (abs(s-t1*t1)>abs(s-t2*t2)) x1=t2,y2=t2,x2=1,y1=abs(s-t2*t2),x3=y3=0;
	else x1=t1+1,y2=t1,x2=0,y1=abs(s-t1*t1),x3=1,y3=0;
	printf("%lld %lld %lld %lld %lld %lld\n",x1,y1,x2,y2,x3,y3);
	return 0;
}

Measured memory_bytes: 256
import heapq


def main():
    N, M = [int(x) for x in input().split()]
    heap = [-int(x) for x in input().split()]
    heapq.heapify(heap)

    for _ in range(M):
        x = heapq.heappop(heap)
        x = -x
        x = x // 2
        x = -x
        heapq.heappush(heap, x)
    print(sum(map(lambda x: -x, heap)))


if __name__ == '__main__':
    main()

Measured memory_bytes: 14180