akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;
LL gcd( LL a, LL b )
{
  LL c;
  while ( a != 0 ) {
     c = a; a = b%a;  b = c;
  }
  return b;
}
LL lcm( LL m, LL n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;

	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

int main(){
	LL t,a,b,c,d;
	cin>>t;
	FOR(cnt,0,t){
		//cerr<<"cnt:"<<cnt<<" ";
		cin>>a>>b>>c>>d;
		LL gcd1=gcd(b,d);
		//cerr<<gcd1<<endl;
		if(a<b||gcd1+c<b||b>d||(gcd1==b&&a%b>c)||(b-gcd1+(a%gcd1)>c)){
			cout<<"No"<<endl;
			continue;
		}else{

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ull unsigned long long
#define mp make_pair
#define F first
#define S second
#define mod 1000000007

int dist[100005];
vector<int> v[100005];
bool viz[100005];
int gelen[100005];

void dfs(int x)
{
    if(!viz[x] && gelen[x] == 0)
    {
        viz[x] = true;
        for(auto y: v[x])
        {
            gelen[y]--;
            dist[y] = max(dist[y] , dist[x]+1);
            if(gelen[y] == 0)
            {
                dfs(y);
            }
        }
    }
}


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

    for(int i=1;i<=n;i++)
    {
        v[0].pb(i);
        gelen[i]++;
    }

    int x,y;
    for(int i=0;i<m;i++)
    {
        cin >> x >> y;
        v[x].pb(y);
        gelen[y]++;
    }

    for(int i=0;i<=n;i++)
    {
        dfs(i);
    }

    int ans = -1;
    for(int i=0;i<=n;i++)
        ans = max(ans, dist[i]-1);
    cout << ans << endl;


}


Measured memory_bytes: 7928
L = int(input())
A = [int(input()) for _ in range(L)]

dp = [0, 0, 0, 0, 0]
for a in A:
  cost24 = a % 2 if a > 0 else 2
  cost3 = int(a % 2 == 0)
  nextdp = []
  nextdp.append(dp[0] + a)
  nextdp.append(min(dp[:2]) + cost24)
  nextdp.append(min(dp[:3]) + cost3)
  nextdp.append(min(dp[:4]) + cost24)
  nextdp.append(min(dp) + a)
  dp = nextdp

print(min(dp))

Measured memory_bytes: 11040
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
	int N, T;
	cin >> N >> T;
	vector<int> t(N);
	for(int i=0;i<N;i++) cin >> t[i];
	int result=T;
	for(int i=1;i<N;i++){
		result+=min(T,t[i]-t[i-1]);
	}
	cout << result;
	return 0;
}


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



int main(){
	int n,W;
	cin>>n>>W;
	vector<int> w(n),v(n);
	int value=0;
	for(int i=0;i<n;i++){
		cin>>w[i]>>v[i];
		value+=v[i];
	}
	vector<long long int > dp(value+1,(1e18L+5));
	dp[0]=0;
	for(int i=0;i<n;i++){
		for(int j=value;j>=0;j--){
			if(j>=v[i])
				dp[j]=min(dp[j],w[i]+dp[j-v[i]]);
		}
	}
	int ans=0;
	for(int i=0;i<=value;i++){
		if(dp[i]<=W){
			ans=max(ans,i);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
object Main extends App {
  val in         = new java.util.Scanner(System.in)
  val a, b, c, d = in.nextLong

  def calcGcd(a: Long, b: Long): Long = {
    val r = a % b
    if (r == 0)
      b
    else
      calcGcd(b, r)
  }

  val possibility = b - a + 1
  val minusByC    = (b / c) - ((a - 1) / c)
  val minusByD    = (b / d) - ((a - 1) / d)
  val gcd         = if (c >= d) calcGcd(c, d) else calcGcd(d, c)
  val lcm         = c * d / gcd
  val duplicate   = (b / lcm) - ((a - 1) / lcm)

  val answer = possibility - (minusByC + minusByD - duplicate)

  println(answer)
}


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

typedef long long ll;

#define REP(i, n) for(int i=0; i<(n); i++)
#define REPS(i, n) for(int i=0; i<=(n); i++)
#define FOR(i, a, b) for(int i=a; i<(b); i++)
#define FORS(i, a, b) for(int i=a; i<=(b); i++)
// for container x
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;

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

    if (s[2]!=s[3]) {
        cout << "No";
        return 0;
    }
    if (s[4]!=s[5]) {
        cout << "No";
        return 0;
    }
    cout << "Yes";

    return 0;
}

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

#define int long long

signed main(){
	
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	
//	int t;
//	cin >> t;
//	while(t--){
		int n;
		cin >> n;
		int a[n],ans=0;
		for(int i=0;i<n;i++){
			cin >> a[i];
			if(i%2==0&&a[i]%2==1){
				ans++;
			}
		}
		cout << ans << endl;
//	}
}


Measured memory_bytes: 3608
#include<stdio.h>
int main() {
    int n, m[1001], i, x;
    scanf("%d%d", &n, &x);
    for (i = 0; i < n; i++) {
        scanf("%d", &m[i]);
        x -= m[i];
    }
    int min = 10000, ans = n;
        for (i = 0; i < n; i++) {
            if (m[i] < min) 
                min = m[i];
        }
        ans += x / min;
    printf("%d\n", ans);
    return 0;
}

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

max_val = max(A)
count = A.count(max_val)

subset = list(set(A))
if len(subset) > 1:
  subset.remove(max_val)
  max_val_2 = max(subset)

for i, num in enumerate(A):
  if num < max_val:
    print(max_val)
  else:
    if count > 1:
      print(max_val)
    else:
      print(max_val_2)

Measured memory_bytes: 17168
#include<bits/stdc++.h>
using namespace std;
int main(){
	string S;cin>>S;
	S.at(4)='0';S.at(7)='0';
	if(S<="2019004030"){
		cout<<"Heisei"<<endl;
	}else{
		cout<<"TBD"<<endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

ll mod = 1e9+7 ;
const ld error = 1e-9;
const ld PI = acosl(-1); //const ld PI = acosl(-1)

#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define eq(x, y) (fabs((x)-(y))<error)
#define bt(i) (1LL<<(i))

#define debug(x) cerr<<#x<<" = "<<(x)<<"\n"
#define hoise cerr<<"hoise - "<<__LINE__<<"\n"
#define tham getchar()
mt19937 rng((unsigned)chrono::system_clock::now().time_since_epoch().count()); //mt199937_64 for ll

inline ll MOD(ll x, ll m = mod){
    ll y = x % m;
    return (y >= 0) ? y: y+m;
}

const int inf = 1e9;
const ll infl = 1e18+1;
const int nmax = 1e3+10;
///===========================================  template  =======================================================

int main(){
    FASTIO;

    map<char, int> dx, dy;
    dx['L'] = 0, dy['L'] = +1;
    dx['R'] = 0, dy['R'] = -1;
    dx['D'] = -1, dy['D'] = 0;
    dx['U'] = +1, dy['U'] = 0;

    int n, m, len;
    cin>>n>>m>>len;
    int x, y;
    cin>>x>>y;
    string s, t;
    cin>>s>>t;

    int lx = 1, rx = n;
    int ly = 1, ry = m;

    for(int i = len-1; i>=0; i--){
        lx = min(lx, lx+dx[t[i]]), rx = max(rx, rx+dx[t[i]]);
        ly = min(ly, ly+dy[t[i]]), ry = max(ry, ry+dy[t[i]]);

        lx = max(1, lx), rx = min(n, rx);
        ly = max(1, ly), ry = min(m, ry);

        lx = max(lx, lx+dx[s[i]]), rx = min(rx, rx+dx[s[i]]);
        ly = max(ly, ly+dy[s[i]]), ry = min(ry, ry+dy[s[i]]);
        if(lx > rx || ly > ry){
            cout<<"NO"<<endl;
            return 0;
        }
    }

    if(lx <= x && x <= rx && ly <= y  && y <= ry) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

    return 0;
}


Measured memory_bytes: 920
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 1e5 + 10;
int n , a[N] , b[N] , sz[N] , fa[N];
int F(int x){return fa[x]==x?x:fa[x]=F(fa[x]);}

int main(){
    scanf("%d",&n);
    rep(i,0,n) scanf("%d",a + i) , a[n] ^= a[i];
    rep(i,0,n) scanf("%d",b + i) , b[n] ^= b[i];
    vi A(a , a + n + 1) , B(b , b + n + 1);
    sort(all(A));
    sort(all(B));
    if(A != B) puts("-1");
    else {
        A.erase(unique(all(A)),A.end());
        rep(i,0,n+1) a[i]=lower_bound(all(A),a[i])-A.begin();
        rep(i,0,n+1) b[i]=lower_bound(all(A),b[i])-A.begin();
        int m = sz(A);
        rep(i,0,m) sz[i]=0,fa[i]=i;
        rep(i,0,n+1) if(a[i]!=b[i]){
            int u=F(a[i]),v=F(b[i]);
            if(u==v) sz[u]++;
            else fa[v]=u,sz[u]+=sz[v]+1;
        }
        int special = F(a[n]) , incircle = a[n] != b[n];
        int ans=0;
        rep(i,0,m) if(F(i)==i){
            if(sz[i]) ans+=sz[i]+(i==special?(incircle?-1:0):1);
        }
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 2560
#include <iostream> 
#include <vector> 
#include <algorithm> 
#include <bits/stdc++.h> 
#include <stdlib.h> 
#include <stdio.h> 
#include <functional> 
#include<math.h>
using namespace std;
int wa(int F){
    int count = 0;
    while(F > 0){
        count += F % 10;
        F /= 10;
    }
    return count;
}
int main(void){
    int N;
    cin >> N;
    int res = 10000;
    for(int i = 1; i < N; i++){
        if(wa(i) + wa(N-i) < res){
            res = wa(i) + wa(N-i);
        }
    }
    cout << res << endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 100000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int N;
int X[1010],Y[1010];
int U[1010],V[1010];
int A[40],B[40];
string str = "LDUR";
int main(){
	cin >> N;
	for(int i=0;i<N;i++){
		scanf("%d %d",&X[i],&Y[i]);
		U[i] = X[i]+Y[i];
		V[i] = X[i]-Y[i];
	}
	for(int i=0;i<N;i++){
		if((U[0]&1)!=(U[i]&1)){
			cout << -1 << endl;
			return 0;
		}
	}
	bool flip = false;
	if((U[0]&1)==0){
		for(int i=0;i<N;i++){
			U[i]++;
			V[i]++;
		}
		flip = true;
	}
	if(!flip){
		cout << 31 << endl;
		for(int i=0;i<31;i++){
			printf("%d ",1<<i);
		}
		printf("\n");
		for(int i=0;i<N;i++){
			int a = 0,b = 0;
			if(U[i]<0){
				a=1;
				U[i]*=-1;
			}
			if(V[i]<0){
				b=1;
				V[i]*=-1;
			}
			int s = 0, t = 0;
			for(int j=30;j>=0;j--){
				if(s==0){
					A[j]=1;
					s = 1;
				}else A[j]=0;
				if((U[i]>>j)&1)s=0;
				if(t==0){
					B[j]=1;
					t = 1;
				}else B[j]=0;
				if((V[i]>>j)&1)t=0;	
			}
			for(int j=0;j<31;j++){
				printf("%c",str[(A[j]^a)*2+(B[j]^b)]);
			}
			printf("\n");
		}
	}else{
		cout << 32 << endl;
		for(int i=0;i<31;i++){
			printf("%d ",1<<i);
		}
		printf("1\n");
		for(int i=0;i<N;i++){
			int a = 0,b = 0;
			if(U[i]<0){
				a=1;
				U[i]*=-1;
			}
			if(V[i]<0){
				b=1;
				V[i]*=-1;
			}
			int s = 0, t = 0;
			for(int j=30;j>=0;j--){
				if(s==0){
					A[j]=1;
					s = 1;
				}else A[j]=0;
				if((U[i]>>j)&1)s=0;
				if(t==0){
					B[j]=1;
					t = 1;
				}else B[j]=0;
				if((V[i]>>j)&1)t=0;	
			}
			for(int j=0;j<31;j++){
				printf("%c",str[(A[j]^a)*2+(B[j]^b)]);
			}
			printf("L\n");
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
 
#define mp make_pair
#define sz(x) (int)((x).size())
#define all(x) (x).begin(),(x).end()
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define eb emplace_back
 
typedef pair< int, int > pii;
typedef pair< long long, long long > pll;
typedef long long ll;
typedef unsigned long long ull;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< ll > vll;
typedef vector< vll > vvll;
typedef vector< pii > vpii;
typedef vector< vpii > vvpii;
typedef vector< pll > vpll;
typedef long double ld;
typedef vector< ld > vld;
typedef unsigned int uint;
 
template <uint MD> struct ModInt {
    using M = ModInt;
    const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    const bool operator<(const M& o) const {return v < o.v; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
 
using Mint = ModInt<(int)1e9 + 7>;

int main() { 
    #ifdef BLAT
        freopen("stdin", "r", stdin);
        freopen("stderr", "w", stderr);
    #endif

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);


    int n;
    cin >> n;

    vi ans(n + 1);

    for(int i = 1; i <= 100; ++i) {
        for(int j = 1; j <= 100; ++j) {
            for(int k = 1; k <= 100; ++k) {
                int x = i*i + j*j + k*k + i*j + i*k + j*k;

                if(x <= n) ans[x] ++;
            }
        }
    }

    for(int i = 1; i <= n; ++i) cout << ans[i] << '\n';
    return 0; 
}

Measured memory_bytes: 3612
let rec seq a b = if a >= b then [] else a :: seq (a+1) b

let () = Scanf.scanf "%d %d %d" @@ fun a b k ->
  List.iter (Printf.printf "%d\n") @@
    if (b - a + 1) >= 2*k then
      seq a (a+k) @ seq (b-k+1) (b+1)
    else
      seq a (b+1)

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

typedef long long ll;
const ll INF = 1e18;
const int BIG = 1e9 + 555;
const int maxN = 100 + 5;

int n, m;
ll dist[maxN][maxN];

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

	cin >> n >> m;

	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			dist[i][j] = INF;
		}
	}
	
	for(int i = 1; i <= n; i++){
		dist[i][i] = 0;
	}

	vector<pair<pair<int, int>, ll> > edg;
	for(int i = 0; i < m; i++){
		int u, v;	ll w;	cin >> u >> v >> w;
		edg.push_back(make_pair(make_pair(u, v), w));
		dist[u][v] = dist[v][u] = w;
	}
	
	for(int k = 1; k <= n; k++){
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= n; j++){
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}
	
	int ans = 0;
	for(int id = 0; id < m; id++){
		int u = edg[id].first.first, v = edg[id].first.second;
		ll w = edg[id].second;
		if(w != dist[u][v]){
			ans++;
		}
	}
	
	cout << ans << '\n';

	return 0;
}

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

#define imie(...) " [" <<#__VA_ARGS__<<':'<<(__VA_ARGS__)<<"] "

const int MAX = 1e5;
int arr[100][2];
// long long dp[(int)1e5+6][100];
int n,W;

//recursion + memoization
// long long go(int w,int i){
// 	if(i == n) return 0;
// 	if(dp[w][i]) return dp[w][i];
// 	long long choose = 0;
// 	if(arr[i][0] <= w){
// 		choose = 1ll*arr[i][1] + 1ll*go(w-arr[i][0],i+1);
// 	}
// 	long long notChoose = go(w,i+1);
// 	// cout<< imie(w) imie(i) imie(choose) imie(notChoose) <<'\n';
// 	return dp[w][i] = max(notChoose,choose);
// } 


void maxself(long long &x,long long y){
	x = max(x,y);
}

//tabulation
long long solve(){
	long long dp[W+1] ={0}; // 0...W
	for(int i=0;i<n;i++){//iterate items
		int weight = arr[i][0], val = arr[i][1];
		for(int currWeight=W;currWeight >= weight; currWeight--){
			maxself(dp[currWeight],dp[currWeight-weight]+val);
		}
	}
	return dp[W];
}
int main () {
	#ifndef ONLINE_JUDGE
	    freopen("in.txt","r",stdin);
	    freopen("out.txt","w",stdout);
    #endif
	cin>>n>>W;

	for(int i=0;i<n;i++){
		cin>>arr[i][0]>>arr[i][1];
	}
	// cout<<go(W,0);
	cout<<solve();

	
	

}

Measured memory_bytes: 4384
import math

def is_prime(n):
    if n == 1: return (False, -1)

    for k in range(int(math.sqrt(n)) + 1, 1, -1):
        if n % k == 0:
            return (False, k)

    return (True, 1)

def solve():
    n = int(input())
    p, k = is_prime(n)
    if p:
        print(n-1)
        return
    l = n // k
    print(k + l - 2)
    return
    '''
    half = int(math.sqrt(n))
    for i in range(half, n):
        if n % i == 0:
            a = i
            b = n // i
            print(a + b - 2)
            return
    return 
    '''

if __name__ == '__main__':
    solve()

Measured memory_bytes: 3064
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
         int  a, b;
        Scanner sc = new Scanner(System.in);
        a = sc.nextInt();
        b = sc.nextInt();
        System.out.printf("%d %d %f\n", a/b,a%b,(double)a/(double)b);
    }
        
}



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

int main(void) {
  int n, q;
  cin >> n >> q;
//  map<string, int> sss;
  queue<string> nameq;
  queue<int> timeq;
  //vector<string> names(100000);
  for (int i = 0; i < n; i++)
  {
    string name;
    int time;
    cin >> name >> time;
    //names.at(i) = name;
    //sss[name] = time;
    nameq.push(name);
    timeq.push(time);
  }

  int time = 0, i = 0;
  while(!(nameq.empty() && timeq.empty()) )
  {
    if (timeq.front() <= q) {
      time += timeq.front();
      cout << nameq.front() << " " << time << endl;
      timeq.pop();
      nameq.pop();
    } else {
      time += q;
      timeq.front() -= q;
      timeq.push(timeq.front());
      nameq.push(nameq.front());
      timeq.pop();
      nameq.pop();
    }
  }
  
  
}


Measured memory_bytes: 5620
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
from functools import lru_cache
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7 

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n) 


def main():
    N = int(input())

    res = 0
    for k in range(1, N + 1):
        t = N // k
        res += t * (t + 1) // 2 * k

    print(res)


if __name__ == "__main__":
    main()



Measured memory_bytes: 68716
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

int main() {
  int n;
  cin>>n;
  double x[n],y[n];
  for(int i=0;i<n;i++){
    cin>>x[i]>>y[i];
  }
  int a[n];
  for(int i=0;i<n;i++) a[i]=i;
  double sum=0;
  do{
    for(int i=0;i<n-1;i++){
      sum+=sqrt((x[a[i+1]]-x[a[i]])*(x[a[i+1]]-x[a[i]])+(y[a[i+1]]-y[a[i]])*(y[a[i+1]]-y[a[i]]));
    }
  }while(next_permutation(a,a+n));
  int mul=1;
  for(int i=1;i<=n;i++){
    mul*=i;
  }
  cout<<fixed<<setprecision(7)<<sum/(double)mul<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;

int main() {
    int N, K, R, S, P;
    string T;
    cin >> N >> K >> R >> S >> P >> T;
    int ans = 0;
    for(int i = 0; i < N; i++) {
        if(T[i] == 'r') {
            ans += (i < K || T[i - K] != 'r') ? P : 0;
            if(i >= K && T[i - K] == 'r') {
                T[i] = 'x';
            }
        } else if(T[i] == 's') {
            ans += (i < K || T[i - K] != 's') ? R : 0;
            if(i >= K && T[i - K] == 's') {
                T[i] = 'x';
            }
        } else if(T[i] == 'p') {
            ans += (i < K || T[i - K] != 'p') ? S : 0;
            if(i >= K && T[i - K] == 'p') {
                T[i] = 'x';
            }
        }
    }

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

Measured memory_bytes: 512
#include<iostream>
#include<cmath>
#include<cstring>

using namespace std;

int main()
{
	char a[101];
	long long k;
	cin>>a>>k;
	int i=0;
	for (;i<k;i++)
	{
		if (a[i]!='1')
			break;
	}
	if (i==k)
		i--;
	cout<<a[i]<<endl;
	return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE MultiWayIf #-}

import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)

main :: IO ()
main = do
    [x, a, b] <- map (fst . fromJust . B.readInt) . B.words <$> B.getLine
    putStrLn $ if | b - a <= 0 -> "delicious"
                  | b - a <= x -> "safe"
                  | otherwise  -> "dangerous"


Measured memory_bytes: 380
#include<iostream>
#include<cmath>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<cstdlib>
#include<queue>
#include<list>
using namespace std;

int main(){
    int a, b, c, d;
    cin>>a>>b>>c>>d;
    cout<<max(a*b,c*d)<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5;
const ll mod=1e9+7;
int main()
{
    string s;
    while(cin>>s)
    {
        if(s[0]!='A')
        {
            puts("WA");
            continue;
        }
        int num=0;
        for(int i=2;i<s.size()-1;i++)
        {
            if(s[i]=='C')
                num++;
        }
        if(num!=1)
        {
            puts("WA");
            continue;
        }
        num=0;
        for(int i=0;i<s.size();i++)
        {
            if(s[i]>='A'&&s[i]<='Z')
                num++;
        }
        if(num!=2)
        {
            puts("WA");
            continue;
        }
        puts("AC");
    }
    return 0;
}

Measured memory_bytes: 256
N,K=map(int,input().split())
X=list(map(int,input().split()))
def time(i):
    if X[i]*X[i+K-1]<0:
        return min(abs(X[i]),abs(X[i+K-1]))+abs(X[i])+abs(X[i+K-1])
    else:
        return max(abs(X[i]),abs(X[i+K-1]))
r=10**9
for i in range(N-K+1):
    r=min(r,time(i))
print(r)

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

int main() {
  string s;
  cin >> s;
  int n  = s.size();
  ll sum = 0;

  map<string, int> m;
  for (int x = 0; x <= (1 << n); x++) {
    vector<ll> arr;
    string num = "";
    string str = "";
    for (int i = 0; i < n; i++) {
      num += s[i];
      str += s[i];
      if (x & (1 << i) && i != n - 1) {
        str += '+';

        arr.push_back(stoi(num));
        num = "";
      }
    }
    if (m[str] == 0) {
      if (num != "") arr.push_back(stoll(num));
      for (int i = 0; i < arr.size(); i++)
        sum += arr[i];
      m[str]++;
    }
  }
  cout << sum << endl;
}

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

const int N_MAX = 50;
int N;

const int A_MAX = 50;
int A;

int x[N_MAX + 1];

typedef long long ll;

ll dp[N_MAX + 1][N_MAX + 1][(N_MAX) * (A_MAX) + 1];

int main()
{
    dp[0][0][0] = 1;

    cin >> N;
    cin >> A;

    int Max = A;

    for(int i = 0;i < N;i++)
    {
        cin >> x[i];
        Max = max(Max,x[i]);
    }

    for(int i = 0;i <= N_MAX;i++)
    {
        for(int c = 0;c <= N_MAX;c++)
        {
            for(int n = 0;n <= N_MAX * A_MAX;n++)
            {
                if(i == 0 && c == 0 && n == 0) continue;
                dp[i][c][n] = 0;
                if(i >= 1)
                {
                    dp[i][c][n] += dp[i - 1][c][n];
                    if(c >= 1 && n - x[i - 1] >= 0)
                    {
                        dp[i][c][n] += dp[i - 1][c - 1][n - x[i - 1]];
                    }
                }

            }
        }
    }

    ll result = 0;
    for(int i = 1;i <= N;i++)
    {
        result += dp[N][i][A * i];
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 51072
n=int(input())
h=[0]+list(map(int,input().split()))
dp=[0]*(n+1)
dp[2]=abs(h[2]-h[1])
for i in range(3,n+1):
    dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]))
print(dp[n])

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

int main(){
  int s;
  cin >> s;
  bool a = true;
  int i = 1;
  vector<int> vec(1);
  vec.at(0) = s;
  
  while(a){
    if(s %2 == 0){
      s = s / 2;
    }
    else{
      s = 3*s + 1;
    }
    i++;
    vec.push_back(s);
    for(int j=0; j<vec.size()-2; j++){
      if(vec.at(j) == s){
        a = false;
      }
    }
  }
  cout << i << endl;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Apolloliu
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

using namespace std;

void get() {

}

typedef long long ll;
vector<ll>a;
bool vis[123456];
unordered_set<int>s;
int l, r;
int N, K;
ll res;
bool go(int cur){
	return cur >= 1 && cur <= N;
}
static int Times = 0;
class CCandles {
public:
	void solve(std::istream& in, std::ostream& out) {
		in >> N >> K;
		ll x;
		memset(vis, 0, sizeof(vis));
		a.clear();
		sort(a.begin(), a.end());
		for (int i = 0; i < N; ++i) {
			in >> x;
			a.push_back(x);
		}
		bool flag = false;
		res = 1e16 + 1;
		ll sum = 0;
		cerr << "case " << Times++ <<'\n';
		if(K == 1){
            for (int i = 0; i < N; ++i) {
                res = min(res, a[i]);
            }
            out << res << '\n';
            return ;
		}
		for (int i = 1; i < N; ++i) {
			sum += abs(a[i] - a[i-1]);
			if(i >= K - 1){
				r = i, l = i - (K - 1);
//				int cur = lower_bound(a.begin()+l, a.begin()+r, 0) - a.begin();
//				if(!a[cur])res = min(res, sum);
//				else
                res = min(res, sum + min(abs(a[l]), abs(a[r])));
//				cerr << i << " " << sum << endl;
			}
			if(i >= K - 1) {
				sum -= abs(a[i - K + 1] - a[i - K + 2]);
			}
		}
		out << res << '\n';
	}
};


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	CCandles solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

Measured memory_bytes: 1528
N, K = map(int, input().split())
A = list(map(int, input().split()))
sumA = sum(A)

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort(reverse=True)
    return divisors

divs = make_divisors(sumA)

for i in divs:
    mod = []
    for j in range(N):
        mod.append(A[j] % i)
    mod.sort(reverse=True)
    tmp = sum(mod) // i # -する数
    tmp = tmp * i - sum(mod[:tmp])  # -する合計数
    if tmp <= K:
        ans = i
        break

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

int main(){
    char a;
    cin >> a;
    if('a' <= a && a <= 'z') cout << 'a' << endl;
    else cout << 'A' << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    string s;
    cin >> s;
    bool flag = true;
    rep(i, s.size()) {
        if ((i + 1) % 2 == 0 && s[i] == 'R')
            flag = false;
        else if ((i + 1) % 2 == 1 && s[i] == 'L')
            flag = false;
    }
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

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

int main(){
  int N;
  cin>>N;
  vector<int> P(N);
  for(int i=0;i<N;i++){
    cin>>P.at(i);
  }
  
  int x=P.at(0);
  int count=0;
  for(int i=0;i<N;i++){
    if(P.at(i)<=x){
      count++;
      x=P.at(i);
    }
  }
  
  cout<<count<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
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; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

void  base_num(ll data,ll base){
    if(data==0) return;
    ll next=abs(data)%abs(base);
    if(data<0) next=(abs(base)-next)%abs(base);
    base_num((data-next)/base,base);
    cout << next;
}



int main(){
    ll n,x,ans=0;
    cin >> n >> x;
    ll a[n];
    for (ll i=0;i<n;i++){
        cin >> a[i];
    }
    for (ll i=1;i<n;i++){
        ans+=max(a[i-1]+a[i]-x,0LL);
        a[i]=min(a[i],max(x-a[i-1],0LL));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Scanner;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        SyntheticKadomatsu solver = new SyntheticKadomatsu();
        solver.solve(1, in, out);
        out.close();
    }

    static class SyntheticKadomatsu {
        List<Integer> l;
        List<Integer> abc;
        int n;
        int a;
        int b;
        int c;
        int result = Integer.MAX_VALUE;

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            n = in.nextInt();
            a = in.nextInt();
            b = in.nextInt();
            c = in.nextInt();
            l = new ArrayList<>();
            abc = new ArrayList<>();

            abc.add(a);
            abc.add(b);
            abc.add(c);

            for (int i = 0; i < n; i++) {
                l.add(in.nextInt());
            }

            for (int bit = 0; bit < (1 << (2 * n)); bit++) {
                List<List<Integer>> d = new ArrayList<>();
                // a,b,c,none
                for (int i = 0; i < 4; i++) {
                    d.add(new ArrayList<>());
                }
                for (int i = 0; i < n; i++) {
                    int index = (bit >> (2 * i)) & 3;
                    d.get(index).add(l.get(i));
                }

                if (!isValid(d)) {
                    continue;
                }
                result = Math.min(result, score(abc, d));
            }

//        recursive(0, 0, 0, 0, 0);
            out.println(result);
        }

        public boolean isValid(List<List<Integer>> d) {
            for (int i = 0; i < 3; i++) {
                if (d.get(i).size() == 0) {
                    return false;
                }
            }
            return true;
        }

        public int score(List<Integer> abc, List<List<Integer>> d) {
            int score = 0;
            for (int i = 0; i < 3; i++) {
                score += 10 * (d.get(i).size() - 1);
                int total = 0;
                for (Integer num : d.get(i)) {
                    total += num;
                }
                score += Math.abs(abc.get(i) - total);
            }
            return score;
        }

    }
}



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

#ifdef DBG
void debug_(){ cout << endl; }
template<typename T, typename... Args>
void debug_(T&& x, Args&&... xs){
	cout << x << " "; debug_(forward<Args>(xs)...);
}
#define dbg(...) debug_(__VA_ARGS__);
#else
#define dbg(...) 
#endif

int main() {
	ios_base::sync_with_stdio(false);
	ll X;
	cin >> X;

	ll a = 100;
	for(int i=0; i<100000; i++){
		a = ll(a*1.01);
		if(a>=X){
			cout << i+1 << endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 3648
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<cmath>
#define MN 250005
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const ll M1=233;
const ll mod=4179340454199820289ll;
void add(ll &x,ll y){(x+=y)>=mod?x-=mod:0;}
void dec(ll &x,ll y){(x-=y)<0?x+=mod:0;}/*
ull mul(ull x, ull y)
{
	x = (x % mod + mod) % mod;
	y = (y % mod + mod) % mod;
	return (x * y - (ll)((long double)x / mod * y) * mod + mod) % mod;
}*/
ll mul(ll x,ll y){
	ll tmp=0;
	while(y){
		if(y&1)add(tmp,x);
		add(x,x);y>>=1;
	}return tmp;
}
ll qpow(ll x,ll y){
	ll tmp=1;
	while(y){
		if(y&1)tmp=mul(tmp,x);
		x=mul(x,x);y>>=1;
	}return tmp;
}
int n,pos[MN];char s[MN];
map<ll,int> mp;
ll lh[MN],rh[MN],fac[MN<<1],ans;
int main(){
	scanf("%d%s",&n,s+1);/*fac[0]=1;
	for(int i=1;i<=2*n;i++)fac[i]=mul(fac[i-1],M1);
	for(int i=1;i<=n;i++){
		pos[i]=pos[i-1],lh[i]=lh[i-1];
		if(s[i]=='<')pos[i]++;
		else if(s[i]=='>')pos[i]--;
		else if(s[i]=='+')add(lh[i],fac[n+pos[i]]);
		else if(s[i]=='-')dec(lh[i],fac[n+pos[i]]);
		mp[lh[i]]++;
	}ans+=mp[lh[n]];ull tmp=lh[n];
	for(int i=1;i<=n;i++){
		if(s[i]=='<')tmp=mul(tmp,M1);
		else if(s[i]=='>')tmp=mul(tmp,inv);
		else if(s[i]=='+')add(tmp,fac[n+pos[i]]);
		else dec(tmp,fac[n+pos[i]]);
		ans+=mp[tmp];mp[lh[i]]--;
	}*/ll X=1,Y=0,x=M1,y=qpow(x,mod-2);
	for(int i=1;i<=n;++i)
	{
		lh[i]=lh[i-1];
		if(s[i]=='+')add(lh[i],X);
		if(s[i]=='-')dec(lh[i],X);
		if(s[i]=='<')X=mul(X,x);
		if(s[i]=='>')X=mul(X,y);
		++mp[lh[i]];
	}X=1;
	for(int i=1;i<=n;++i)
	{
		ll tmp=mul(lh[n],X);add(tmp,Y);
		ans+=mp[tmp];
		if(s[i]=='+')add(Y,X);
		if(s[i]=='-')dec(Y,X);
		if(s[i]=='<')X=mul(X,x);
		if(s[i]=='>')X=mul(X,y);
		--mp[lh[i]];
	}
	printf("%lld\n",ans);
}

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;

int t[10000];

int f(int n)
{
    if(n % 2 == 0) return n / 2;
    else return 3 * n + 1;
}

void solve()
{
    int s; cin >> s;
    int m = 1;
    t[s]++;
    while(true)
    {
        m++;
        s = f(s);
        t[s]++;
        if(t[s] == 2)
        {
            cout << m << endl;
            return;
        }
    }
}
    
int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }

int N;
string a0;

string ask(int i) {
    cout << i << endl;
    string res; cin >> res;
    return res;
}

void f(int l, int r) {
    int mid = (l + r) / 2;
    string res = ask(mid);
    if (res == "Vacant") return;
    if ((mid % 2 == 0 && a0 == res) || (mid % 2 == 1 && a0 != res)) {
        f(mid+1, r);
    } else {
        f(l, mid);
    }
}

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

    cin >> N;
    a0 = ask(0);
    if (a0 == "Vacant") return 0;

    f(1, N);

    return 0;
}

Measured memory_bytes: 852
#include<iostream>
#include<string>
#include<string.h>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
using namespace std;
int n;
long long a[200500];
int main()
{
    ios::sync_with_stdio(false);
    int k,n,i;
    cin >> n >> k;
    for (i=1;i<=n;i++)
    {
        cin >> a[i];
    }
    long long ans=1e18+7;
    for (i=1;i+k-1<=n;i++)
    {
        long long tmp=a[i+k-1]-a[i];
        if ((a[i]<0) && (a[i+k-1]<0)) tmp+=abs(a[i+k-1]);
        if ((a[i]>0) && (a[i+k-1]>0)) tmp+=a[i];
        if ((a[i]<0) && (a[i+k-1]>0)) tmp+=min(-a[i],a[i+k-1]);
        ans=min(ans,tmp);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define lamsort(v,p) sort(v.begin(),v.end(),[](p a, p b){return a.num < b.num;});
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
const long long LLINF = 1LL<<60;
const int INF = 1e9;
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; }
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m; cin >> n >> m;
    string s; cin >> s;
    reverse(ALL(s));
    vector<int> f;
    rep(i,s.size()) {
        if(s[i]=='0') f.push_back(i);
    }
    vector<int> ans;
    int now = 0;
    while(now!=n) {
        int next = *(--upper_bound(ALL(f), now+m));
        if(now==next) {
            cout << -1 << endl;
            return 0;
        }
        ans.push_back(next-now);
        now = next;
    }
    reverse(ALL(ans));
    rep(i,ans.size()) cout << ans[i] << endl;

    return 0;
}

Measured memory_bytes: 1480
import heapq

N, M = map(int,input().split())
A = []
for x in list(map(int, input().split())):
    heapq.heappush(A, -x)

for i in range(M):
    heapq.heapreplace(A, (A[0]+1)//2)
#    print(A)
ans = -sum(A)
print(ans)


Measured memory_bytes: 14180
import sys
n,Y = map(int,input().split())
for x in range(n+1):
    for y in range(n-x+1):
        z = n-(x+y)
        if z >= 0 and 10000*x+5000*y+1000*z == Y:
            print(x,y,z)
            sys.exit()
print(-1,-1,-1)

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

int main(){
  long long N, pp=2,p=1,now;
  cin >> N;
  for(int i = 1;i<N;i++){
    now = pp + p;
    pp = p;
    p = now;
  }
  printf("%lld\n", p);
}
    
    
  

Measured memory_bytes: 256
n = gets.to_i
pi = gets.chomp.split(' ').map(&:to_i)
qi = gets.chomp.split(' ').map(&:to_i)

i = 0
a,b = 0,0

(1..n).to_a.permutation(n) do |val|

		a = i if val == pi
		b = i if val == qi
		i += 1
end

puts (a-b).abs

Measured memory_bytes: 2172
from collections import deque
while 1:
    n,a,b,c,x = map(int,input().split())
    if n == 0 and a == 0 and b == 0 and c == 0 and x == 0:
        break
    y = list(map(int,input().split()))
    flame = 0
    ind = 0
    for i in range(10000+1):
        if x == y[ind]:
            ind += 1
        if ind == n:
            break
        flame += 1
        x = (a*x+b) % c 
    if ind == n:
        print(flame)
    else:
        print(-1)


Measured memory_bytes: 5992
def opt_change(n):
	change = [0,0,0,0]
	purse = (10,50,100,500)
	for i in range(4):
		change[3-i] = n / purse[3-i]
		n = n % purse[3-i]
	return change

flag = 0
while 1:
	price = int(raw_input())
	if price == 0:
		break
	if flag == 0:
		flag = 1
	else :
		print "" 
	purse_num = map(int,raw_input().split())
	purse = [10,50,100,500]
	own = sum([purse[i] * purse_num[i] for i in range(4)])
	result = opt_change(own-price)
	for i in range(4):
		num = 0 if purse_num[i] <= result[i] else (purse_num[i] - result[i])
		if num != 0:
			print purse[i], num

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

int main() {
  int n;
  while(cin >> n, n) {
    int ans = 0;
    for (int i=0; i*i*i < n*n*n; i++) {
      for (int j=0; i*i*i+j*j*j < n*n*n; j++) {
        ans = max(ans, i*i*i+j*j*j);
      }
    }
    cout << n*n*n - ans << endl;
  }
}

Measured memory_bytes: 864
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

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

#define MOD 1000000007

void solve(int test_case) {
	string s;
	cin>>s;
	if(s=="SUN")cout<<7;
	else if(s=="MON")cout<<6;
	else if(s=="TUE")cout<<5;
	else if(s=="WED")cout<<4;
	else if(s=="THU")cout<<3;
	else if(s=="FRI")cout<<2;
	else if(s=="SAT")cout<<1;
	
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


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

int main(){
  int N, K; cin >> N >> K;
  vector<int> H(N); rep(i, N) cin >> H[i];
  sort(H.rbegin(), H.rend());

  long long ans = 0;
  for (int i = K; i < N; i++) {
    ans += H[i];
  }

  cout << ans << endl;
}


Measured memory_bytes: 1024
const teststr = 
"""
8 6 9 1
AC
BC
AB
BC
AC
BC
AB
AB
"""

function lines()
  Channel{String}(32) do ch
    ll = readlines()
    lines = isempty(ll) ? split(teststr, "\n") : ll
    for s in lines
      put!(ch, s)
    end
  end
end

function main()
  ch = lines()
  N,A,B,C = parse.(Int, split(take!(ch)))
  c = zeros(Int, 3, N)
  strs=String[]
  for i in 1:N
    str = take!(ch)
    push!(strs, str)
    @views c[:,i] = str=="AB" ? [1,-1,0] :
                    str=="AC" ? [1,0,-1] :
                                [0,1,-1]
  end
  ss = ones(Int, N)
  hs = zeros(Int, 3, N)
  @views hs[:,1] .= [A,B,C]
  que = [(1,-1), (1,1)]
  while !isempty(que)
    n, s = pop!(que)
    abc = s>0 ? @views(hs[:,n] .+ c[:,n]) : @views(hs[:,n] .- c[:,n])
    any(abc .< 0) && continue
    ss[n] = s
    if n == N
      println("Yes")
      for i in 1:N
        println(strs[i][ss[i]==1 ? 1 : 2])
      end
      exit(0)
    end
    @views hs[:,n+1] .= abc
	push!(que, (n+1,-1), (n+1,1))
  end
  println("No")
end

main()

Measured memory_bytes: 273264
N = int(input())
A = [int(i) for i in input().split()]
A.sort()
T = max(A)/2
M = max(A)
S = A[0]

for i in range(N-1):
  if M >= abs(A[i] - T):
    M = abs(A[i] - T)
    S = A[i]

print(str(A[N-1])+" "+str(S))

Measured memory_bytes: 14052
#include <iostream>
using namespace std;
using i64 = long long;

int main() {
    i64 n, d;
    i64 x, y;
    i64 ans = 0;

    cin >> n >> d;
    for (int i = 0; i < n; i++) {
        cin >> x >> y;
        if (x*x + y*y <= d*d) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628