akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;

//#define int long long
//using ll = boost::multiprecision::cpp_int;
using ll = long long;
//const int INF = 1e9;//INT_MAX=1<<31-1=2147483647
const ll INF = (ll)1e18;//1<<63-1=9223372036854775807
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
#ifdef LOCAL_ENV
	#define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
	#define debug(var)
#endif
#define p(var) std::cout<<var<<std::endl
#define PI (acos(-1))
#define rep(i, n)   for(ll i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(ll i=1, i##_length=(n); i<=i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define pb push_back
inline bool isnatural(double a) { return a>=0 && ceil(a)==floor(a); }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	for (int i = 0, len = v.size(); i < len; ++i){
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	for (int i = 0, len = vv.size(); i < len; ++i){
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr){
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/


ll N;
queue<pair<ll,ll>> que;
using Graph = vector<vector<ll>>;
ll kuro=0,shiro=0;
vector<ll> dist;
void bfs(Graph &g){
	while (!que.empty()) {
		auto v = que.front(); // キューから先頭頂点を取り出す
		que.pop();
		debug(v);
		// v から辿れる頂点をすべて調べる
		for (ll nextv : g[v.first]) {
			if (dist[nextv] != 0) continue; // すでに発見済みの頂点は探索しない

			// 新たな頂点 nextv について距離情報を更新してキューに追加する
			dist[nextv] = v.second;
			que.push(make_pair(nextv,v.second));
			if(v.second==1)kuro++;
			else shiro++;
		}
	}
}


signed main() {
	ll N;
	cin>>N;
	vector<ll> ans(2*N-1,0);
	Graph g(N);
	dist.assign(N, 0);
	rep(i,N-1){
		ll a,b;
		cin>>a>>b;
		a--;b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	que.push(make_pair(0,1));
	que.push(make_pair(N-1,-1));
	debug(g);
	bfs(g);
	debug(kuro);debug(shiro);
	if(kuro>shiro)p("Fennec");
	else p("Snuke");
	return 0;
}


Measured memory_bytes: 8832
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll mo = 1000000007;
const ll INF = 1LL << 60; //MAX 9223372036854775807
ll ans = INF;

int main()
{
ll l,r;
cin >> l>>r;
if(r-l>=2019){
cout << 0 << endl;
return 0;
}
for (ll i = l; i <= r; i++){
    if(i%2019==0){
        cout << 0 << endl;
        return 0;
    }
}

r%=2019;
l%=2019;
for (ll i = l; i <= r; i++)for (ll j = l; j <= r; j++)
{
    if(i==j)continue;
    ans=min((i*j)%2019,ans);
}


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


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

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
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; }

using ll = long long;
using P = pair<ll, ll>;

constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

class A01Matrix {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int h, w, a, b; cin >> h >> w >> a >> b;
      rep(i, h) {
        rep(j, w) {
          cout << (i<b ^ j<a);
        }
        cout << '\n';
      }
    }
};

signed main() {
  A01Matrix solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N, K;
vector<ll> A;
ll v[60], vv[60];
int main () {
    cin >> N >> K;
    for (int i = 0; i < N; i++) {
        ll a;
        cin >> a;
        A.push_back(a);
        for (int j = 0; j < 60; j++) {
            if ((1LL << j) & a) {
                v[j]++;
            }
        }
    }
    ll ans = 0;
    for (int i = 0; i < 60; i++) {
        vv[i] = max(v[i], N-v[i])*(1LL << i);
        if (i) {
            vv[i] += vv[i-1];
        }
        if ((1LL << i) & K) {
            ans += (N-v[i])*(1LL << i);
        }
        else {
            ans += v[i]*(1LL << i);
        }
    }
    ll res = 0;
    for (int i = 59; i >= 0; i--) {
        if ((1LL << i) & K) {
            ans = max(ans, res+v[i]*(1LL << i)+((i > 0)?vv[i-1]:0));
            res += (N-v[i])*(1LL << i);
        }
        else {
            res += v[i]*(1LL << i);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1400
#include<iostream>

using namespace std;

int add(int a) {
	int sum = 0;
	//桁数を求める
	while (a!=0)
	{
		sum += a%10;
		a /= 10;
		
	}
	return(sum);
}


int main()
{
	int n, num,time;
	
	cin >> n;
	int min = n;

	//総当たり
	for (int i = 1; i < (n/2)+1; i++)
	{
		num = add(i)+add(n-i);
		//cout << num << endl;
		if (num < min) min = num;
	}

	cout << min << endl;

    return 0;
}

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

int main() {
	int n, m;
	cin >> n >> m;
	vector<ll> a(n), b(n), c(m), d(m);
	rep(i, n) cin >> a[i] >> b[i];
	rep(i, m) cin >> c[i] >> d[i];
	rep(i, n) {
		int nearest_checkpoint = 0;
		int min_distance = 1001001001;
		rep(j, m) {
			int now = abs(a[i] - c[j]) + abs(b[i] - d[j]);
			if(min_distance > now) {
				min_distance = now;
				nearest_checkpoint = j+1;
			}
		}
		cout << nearest_checkpoint << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import numpy as np
import sys
input = sys.stdin.readline

N, K = map(int, input().split())
A = np.sort(list(map(int, input().split())))
F = np.sort(list(map(int, input().split())))[::-1]

t_max = A[-1] * F[0]
t_min = -1

while t_max > t_min + 1:
    t_mid = (t_max + t_min) // 2
    K_tmp = np.sum(np.maximum(A - t_mid // F, 0))
    if K_tmp <= K:
        t_max = t_mid
    else:
        t_min = t_mid

print(t_max)


Measured memory_bytes: 37224
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back

void solve(){
    int n; cin >> n;
    map<char, int> mp;
    for(char c='a'; c<='z'; c++){
        mp[c] = 100;
    }
    
    REP(i, n){
        string s;
        cin >> s;
        map<char, int> mpp;
        for(char c='a'; c<='z'; c++){
            mpp[c] = 0;
        }
        REP(j, s.size()){
            mpp[s[j]] += 1;  
        }
        for(char c='a'; c<='z'; c++){
            mp[c] = min(mp[c], mpp[c]);
        }
    }
    string res = "";
    for(auto it=mp.begin(); it!=mp.end(); it++){
        if(it->second != 100 && it->second != 0){
            REP(i, it->second){
                res += it->first;
            }
        }
    }
    cout << res << endl;

}

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

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int x, y;
  scanf("%d %d", &x, &y);
  if(x == 1 || x == 3 || x == 5 || x == 7 || x == 8 || x == 10 || x == 12) {
    if(y == 1 || y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12) {
      printf("Yes");
    } else {
      printf("No");
    }
  } else if (x == 4 || x == 6 || x == 9 || x == 11) {
    if (y == 4 || y == 6 || y == 9 || y == 11) {
      printf("Yes");
    } else {
      printf("No");
    }
  } else if (x == 2) {
    if (y == 2) {
      printf("Yes");
    } else {
      printf("No");
    }
  }
  return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<iostream>
#include<string>

using namespace std;

int main(void) {

	string f, b;

	cin >> f >> b;

	for (int i = 0; i < f.size(); i++)
	{
		if (b.size() != f.size() && i == f.size()-1) {
			cout << f[i];
		}
		else {
			cout << f[i] << b[i];
		}
	}

	cout << "\n";

	return 0;
}

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

int main(){
    int N,M,t;
    long long res=0;
    cin >> N >> M;

    if (M>1){
        vector<int> v(M,0);
        vector<int> v2(M,0);

        for (int i=0;i<M;i++){
            cin >> v[i];
        }
        sort(v.begin(),v.end());
        res = v[M-1] - v[0];
        for (int i=1;i<M;i++){
        t = v[i]-v[i-1];
        v2[i] = t;
        }
        sort(v2.rbegin(),v2.rend());

        t = min(N-1,M);
        for (int j=0;j<t;j++){
            res -= v2[j];
        }
    }
    
    cout << res << endl;
    }
    //sort(v.rbegin(), v.rend(), [](auto& x, auto& y){return x[1] < y[1];});

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE

struct RollingHash{
  typedef unsigned long long ull;
  string S;
  ull B;
  Int len;
  vector<ull> hash,p;
  RollingHash(){}
  RollingHash(string S_, ull B_ = (1e9) + 7):
    S(S_), B(B_), len(S.length()), hash(len+1), p(len+1){
    hash[0] = 0; p[0] = 1;
    for(Int i=0;i<len;i++){
      hash[i+1] = hash[i] * B + S[i];
      p[i+1] = p[i] * B;
    }
  }
  
  ull find(Int l,Int r){
    return hash[r] - hash[l] * p[r - l];
  }
};

signed main(){
  auto comp=[&](RollingHash &s,RollingHash &t){
	      Int n=s.len,m=t.len;
	      if(n==m&&s.find(0,n)==t.find(0,m)) return false;
	      Int l=-1,r=min(n,m)+1;
	      while(l+1<r){
		Int k=(l+r)>>1;
		if(s.find(0,k)==t.find(0,k)) l=k;
		else r=k;
	      }
	      if(l==min(n,m)) return n<m;
	      return s.S[l]<t.S[l];
	    };
  
  cin.tie(0);
  ios::sync_with_stdio(false);
  Int n,m;
  cin>>n>>m;

  vector<string> dic(n);
  vector<RollingHash> rhs(n);
  for(Int i=0;i<n;i++){
    cin>>dic[i];
    rhs[i]=RollingHash(dic[i]);
  }
  
  vector<Int> ord(n);
  iota(ord.begin(),ord.end(),0);
  auto scomp=[&](Int i,Int j){return comp(rhs[i],rhs[j]);};
  sort(ord.begin(),ord.end(),scomp);

  //for(Int i=0;i<n;i++) cout<<dic[ord[i]]<<endl;

  vector<string> ps(m),ss(m);
  for(Int i=0;i<m;i++) cin>>ps[i]>>ss[i];
  
  vector<Int> ans(m,0);
  vector<vector<Int> > ls(n),rs(n);
  for(Int i=0;i<m;i++){
    RollingHash rhp(ps[i]);
    Int l=-1,r=n;
    while(l+1<r){
      Int k=(l+r)>>1;
      if(comp(rhs[ord[k]],rhp)) l=k;
      else r=k;
    }
    //cout<<l<<":"<<r<<endl;
    ps[i].back()++;
    rhp=RollingHash(ps[i]);
    ps[i].back()--;

    Int L=-1,R=n;
    while(L+1<R){
      Int k=(L+R)>>1;
      if(comp(rhs[ord[k]],rhp)) L=k;
      else R=k;
    }
    if(r==R) continue;
    //cout<<r<<":"<<L<<endl;
    ls[r].emplace_back(i);
    rs[L].emplace_back(i);
  }
  
  using ull = RollingHash::ull;
  using P = pair<Int, ull>;
  map<P, Int> cnt;

  for(Int i=0;i<n;i++){
    for(Int u:ls[i]){
      RollingHash rhp(ss[u]);
      ans[u]-=cnt[P(rhp.len,rhp.find(0,rhp.len))];		  
    }

    RollingHash &rh=rhs[ord[i]];
    for(Int j=1;j<=rh.len;j++) cnt[P(j,rh.find(rh.len-j,rh.len))]++;
    
    for(Int u:rs[i]){
      RollingHash rhp(ss[u]);
      ans[u]+=cnt[P(rhp.len,rhp.find(0,rhp.len))];		  
    }
  }
  
  for(Int i=0;i<m;i++) cout<<ans[i]<<endl;
  return 0;
}



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

int main(void){
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    for (int i = sy; i < ty; i++) cout << "U";
    for (int i = sx; i < tx; i++) cout << "R";
    for (int i = ty; i > sy; i--) cout << "D";
    for (int i = tx; i > sx; i--) cout << "L";
    cout << "L";
    for (int i = sy; i <= ty; i++) cout << "U";
    for (int i = sx; i <= tx; i++) cout << "R";
    cout << "DR";
    for (int i = ty; i >= sy; i--) cout << "D";
    for (int i = tx; i >= sx; i--) cout << "L";
    cout << "U";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int i = 1; i <= (int)(x); i++)
#define repr(i, x) for (int i = ((int)(x) - 1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
void solve() {
	string s, t; cin >> s >> t;
	cout << t << s  << endl;
	return;
}

int main() {
	solve();
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 100000+15;
	int a[MAXN] = {0};
int main(){
	int a1,b,c,d;
	cin>>a1>>b>>c>>d;
	a[0] = a1+c; a[1] = a1+d;
	a[2] = b+c; a[3] = b+d;
	sort(a,a+4);
	cout<<a[0]<<endl;
}

Measured memory_bytes: 256
// warm heart, wagging tail,and a smile just for you!
//                                                                     ███████████
//                                                                   ███╬╬╬╬╬╬╬╬╬╬███
//                                                                ███╬╬╬╬╬████╬╬╬╬╬╬███
//                                            ███████████       ██╬╬╬╬╬████╬╬████╬╬╬╬╬██
//                                      █████████╬╬╬╬╬████████████╬╬╬╬╬██╬╬╬╬╬╬███╬╬╬╬╬██
//                               ████████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬██╬╬╬╬╬╬╬██
//                             ████╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬╬╬╬╬╬██
//                           ███╬╬╬█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬███╬╬╬╬╬╬╬█████
//                         ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬████████╬╬╬╬╬██
//                       ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬╬╬╬╬███
//                     ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬██
//                 ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬████
//     █████████████╬╬╬╬╬╬╬╬██╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬██████
//   ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬██████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████╬╬╬╬╬╬╬███████████╬╬╬╬╬╬╬╬██╬╬╬██╬╬╬██
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬█╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬██
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬▓▓▓▓▓▓╬╬╬████╬╬████╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬███
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬█████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████████
//   ███╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
//       ██████████████  ████╬╬╬╬╬╬███████████████████████████╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████
//                         ███████                           █████  ███████████████████
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);i--)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<vector<P> > Graph;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

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

  string s;
  cin >> s;

  int n = s.size();

  int ans = 0, cur = 0;
  REP(i,n-1){
    if(s[i] == 'A') cur++;
    else if(s[i] == 'B' && s[i+1] == 'C') ans += cur, i++;
    else cur = 0;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 720
#include<stdio.h>
#define N 100000
typedef struct{
    char name[10];
    int time;
} Process;

Process ps[N];
int head=0;
int tail=0;
int alltime=0;

Process deq(){
    Process res = ps[head];
    if(head + 1 == N){
        head = 0;
    }else {
        head+=1;
    }
    return res;
}

void enq(Process p){
    ps[tail] = p;
    if(tail + 1 == N){
        tail = 0;
    }else {
        tail+=1;
    }
}

void printIt(Process data){
    printf("%s %d\n", data.name, alltime+=data.time);
}


int main(){
    int n, q;
    int i;
    Process data;
    
    scanf("%d%d", &n, &q);
    for(i=0;i<n;i++){
        scanf(" %s%d", data.name, &data.time);
        enq(data);
    }

    while(1){
        if(head == tail) break;
        alltime += q;
        ps[head].time -= q;
        if(ps[head].time <= 0){
            data = deq();
            printIt(data);
        }else {
            data = deq();
            enq(data);
        }
    }

    return 0;

}

Measured memory_bytes: 2160
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <vector>
#include <stdio.h>
#include <fstream>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <algorithm>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <bits/stdc++.h>

#define ff first
#define ss second
#define ll long long
#define pb push_back
#define mp make_pair
#define inf 1000000007
#define mod 1000000007
#define pii pair <int, int>
#define all(x) x.begin(), x.end()
#define FOR(i, x, y) for (int i = x; i <= y; i++)
//#define tr(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)

//using namespace __gnu_pbds;

using namespace std;

//template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

ll a, b, c, d;

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


Measured memory_bytes: 256
# include <algorithm>
# include <iostream>
# include <iterator>
# include <vector>
# include <string>
# include <queue>
# include <stack>
# include <cmath>
# include <set>


using namespace std;


vector<int> ps = {1};


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

    for (int i=1; pow(6, i) <= n; ++i) {
        // if (pow(6, i) > n) continue;
        ps.push_back(pow(6, i));
    }
    for (int i=1; pow(9, i) <= n; ++i) {
        // if (pow(9, i) > n) continue;
        ps.push_back(pow(9, i));
    }
    sort(ps.begin(), ps.end());
    // ok

    vector<int> dp(n+1);
    fill(dp.begin(), dp.end(), 1e8);
    dp[0] = 0;  // to withdraw 0 yen, it requires 0 operation
    // ok

    for (int i=0; i<=n; ++i) {
        for (int p: ps) {
            if (i >= p) {
                // FIXME (himkt) I may not require dp[i-1], why?
                dp[i] = min(dp[i], min(dp[i-1], dp[i-p]) + 1);
            }
        }
    }

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



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

int main() {
 string s,t;
 cin>>s>>t;
 if(s.size()>t.size()){
   cout<<"GREATER"<<endl;
 }
 if(s.size()<t.size()){
   cout<<"LESS"<<endl;
 }
 if(s.size()==t.size()){
   bool f=true;
   rep(i,s.size()){
     if(s.at(i)>t.at(i)){
       cout<<"GREATER"<<endl;
       f=false;
       break;
     }
     if(s.at(i)<t.at(i)){
       cout<<"LESS"<<endl;
       f=false;
       break;
     }
   }
   if(f){
     cout<<"EQUAL"<<endl;
   }
 }

}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define INF_LL 1e18
#define INF 1e9

#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()

#define fst first
#define snd second

using namespace std;

using ll = long long;
using PII = pair<int, int>;

ll dp[155][10][80];
int main(void){
	int n, m;
	while(cin >> n >> m && (n || m)){
	vector<pair<ll, ll> > s[151];
	REP(i, 155){
		REP(j, 10){
			fill(dp[i][j], dp[i][j]+80, INF_LL);
		}
	}
	REP(i, n){
		int k;
		cin >> k;
		REP(j, k){
			int x, d;
			cin >> x >> d;
			s[i].push_back({x, d});
		}
	}
	REP(i, s[0].size()){
		dp[0][i][0] = 0;
	}
	REP(i, s[1].size()){
		dp[1][i][1] = 0;
	}
	REP(i, n-1){
		REP(j, s[i].size()){
			REP(k, m+1){
				REP(t, s[i+1].size()){
					dp[i+1][t][k] = min(dp[i+1][t][k], dp[i][j][k] + (s[i][j].snd+s[i+1][t].snd)*abs(s[i][j].fst-s[i+1][t].fst));
				}
				if(i < n-2){
					REP(t, s[i+2].size()){
						dp[i+2][t][k+1] = min(dp[i+2][t][k+1], dp[i][j][k] + (s[i][j].snd+s[i+2][t].snd)*abs(s[i][j].fst-s[i+2][t].fst));
					}
				}
			}
		}
	}
	ll res = INF_LL;
	REP(j, s[n-1].size()){
		REP(k, m+1){
			res = min(dp[n-1][j][k], res);
		}
	}
	REP(j, s[n-2].size()){
		REP(k, m){
			res = min(dp[n-2][j][k], res);
		}
	}
	cout << res << endl;
	}
}

Measured memory_bytes: 3952
#include <iostream>
#include <cstring>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N; cin >> N;
    int a[8]; memset(a, 0, sizeof(a));
    int cnt = 0;
    for(int i = 0; i < N; ++i){
        int x; cin >> x;
        if(x < 400) {
            a[0]++;
        }
        else if(x < 800) {
            a[1]++;
        }
        else if(x < 1200) {
            a[2]++;
        }
        else if(x < 1600) {
            a[3]++;
        }
        else if(x < 2000) {
            a[4]++;
        }
        else if(x < 2400) {
            //cout << a[5] << endl;
            a[5]++;
            //cout << a[5] << endl;
        }
        else if(x < 2800) {
            a[6]++;
        }
        else if(x < 3200) {
            a[7]++;
        }
        else{
             cnt++;
        }
    }

    int nnum = 0;
    for(int i = 0; i < 8; ++i){
        if(a[i] == 0) continue;
        nnum++;
    }
    if(nnum == 0) cout << 1 << " " << cnt << endl;
    else cout << nnum << " " << nnum + cnt << endl;
    return 0;
}
//Sawt the editorial

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

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

    // start
    int x, t;
    cin >> x >> t;
    if (x - t < 0)
        cout << 0 << endl;
    else
        cout << x - t << endl;
    // end

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main {
 	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();
		HashSet<String> hash = new HashSet<String>();
		int max = 0;

		for(int i=1; i<N; i++){
			String X = S.substring(0, i);
			String Y = S.substring(i, N);
			hash.clear();
			for(int j=0; j<X.length(); j++){
				String x = X.substring(j, j+1);
				if(Y.contains(x)){
					hash.add(x);
				}
			}
			if(hash.size()>max){
				max = hash.size();
			}
		}
		System.out.println(max);
	}
}


Measured memory_bytes: 37156
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define fir first
#define sec second
#define mod 998244353
#define int long long
#define INF (int)(1e18)
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
typedef pair<int,int> pii;
int add(int x,int y){return x+y>=mod?x+y-mod:x+y;}
int sub(int x,int y){return x-y<0?x-y+mod:x-y;}
int mul(int x,int y){return 1LL*x*y%mod;}
#define N 5005
int f[N][N];
struct Node
{
	int x,y;
};
Node a[N];
bool cmp(Node x,Node y)
{
	return x.x+x.y<y.x+y.y;
}
signed main()
{
#ifdef __LOCAL__
	freopen("in.txt","r",stdin);
#endif
	int n=read();
	for(int i=1;i<=n;i++) a[i].x=read(),a[i].y=read();
	sort(a+1,a+n+1,cmp);
	for(int i=0;i<=n;i++)
	{
		for(int j=1;j<=n;j++) f[i][j]=INF;
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=i;j++)
		{
			f[i][j]=f[i-1][j];
			if(f[i-1][j-1]<=a[i].x)
			{
				f[i][j]=min(f[i][j],f[i-1][j-1]+a[i].y);
			}
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		if(f[n][i]<INF) ans=i;
	}
	cout<<ans<<endl;
#ifdef __LOCAL__
	cout<<"Time Used : "<<clock()<<endl;
#endif
	return 0;
}



Measured memory_bytes: 195968
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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 ll INF=1e18;

int main(){
    ll a,b,c;
    cin >> a >>b >> c;
    if(a+c==2*b) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <math.h>

using namespace std;
int N, Y;

int main(){
    cin >> N >> Y;
    int c1=0, c2=0, c3, b=0;
    c1=Y/10000;
    c2=Y/5000;
    c3=Y/1000;

    for(int i=0;i<=c1;i++){
        for(int j=0;j<=c2;j++){
            int k=N-(i+j);
            if(k>c3 || k<0)break;
            else {
                if(i*10000+j*5000+k*1000==Y){
                    cout << i << " " << j << " " << N-(i+j);
                    b=1;
                    break;
                }
            }
        }
        if(b==1)break;
    }
    if(b == 0){
        cout << -1 << " " << -1 << " " << -1;
    }
    

    cout << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

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

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

void solve(ll N, ll M) {
  cout << min(M / 2, (N * 2 + M) / 4) << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll N;
	ll M;
	scanf("%lld", &N);
	scanf("%lld", &M);
	solve(N, M);
	return 0;
}


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

int main() {
    ll N, K;
    cin >> N >> K;

    vector<ll> a(N);
    for (ll i = 0; i < N; i++) {
        cin >> a[i];
    }

    vector<bool> dp(K + 1, false);
    for (ll i = 0; i <= K; i++) {
        for (ll j = 0; j < N; j++) {
            if (i - a[j] >= 0 && !dp[i - a[j]]) {
                dp[i] = true;
                break;
            }
        }
    }

    cout << (dp[K] ? "First" : "Second") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <math.h>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}*/

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

	int a, b, c, d, e, k;
	cin >> a >> b >> c >> d >> e >> k;

	bool can = true;

	//if (b - a > k || c - b > k || d - c > k || e - d > k) {
	if(e - a > k){
		can = false;
	}

	if (can) cout << "Yay!" << endl;
	else cout << ":(" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <queue>
#include <utility>

using namespace std;

priority_queue<pair<int, int> > h;
int x, y, z, A, B, C, w;
long long ans;

int main() {
    scanf("%d%d%d%d%d", &x, &y, &A, &B, &C);
    while (A--) {
        scanf("%d", &w);
        h.push(make_pair(w, 1));
    }
    while (B--) {
        scanf("%d", &w);
        h.push(make_pair(w, 2));
    }
    while (C--) {
        scanf("%d", &w);
        h.push(make_pair(w, 0));
    }
    z = x + y;
    while (z) {
        pair<int, int> now = h.top();
        h.pop();
        if (now.second == 0) {
            ans += now.first;
            --z;
        } else if (now.second == 1 && x) {
            ans += now.first;
            --x;
            --z;
        } else if (now.second == 2 && y) {
            ans += now.first;
            --y;
            --z;
        }
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 6384
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=2e5+5;
int n,a[maxn],head[maxn],cnt,dp[maxn],ans[maxn];
struct node{
    int to,next;
}e[maxn<<1];
void add(int u,int v){
    e[++cnt].to=v;
    e[cnt].next=head[u];
    head[u]=cnt;
}
void dfs(int son,int fa){
    int pos=lower_bound(dp+1,dp+1+n,a[son])-dp;
    int temp=dp[pos];
    dp[pos]=a[son];
    ans[son]=max(ans[fa],pos);
    for(int i=head[son];i;i=e[i].next){
        if(e[i].to!=fa){
            dfs(e[i].to,son);
        }
    }
    dp[pos]=temp;//回溯
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=1,u,v;i<=n-1;i++){
        scanf("%d %d",&u,&v);
        add(u,v),add(v,u);
    }
    memset(dp,0x3f,sizeof(dp));
    dfs(1,0);
    for(int i=1;i<=n;i++){
        printf("%d\n",ans[i]);
    }
    return 0;
}


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

int main(){
  int64_t n;
  cin >> n;
  vector<int64_t>t(5);
  for(int i=0;i<5;i++)
    cin >> t.at(i);
  sort(t.begin(),t.end());
  cout << n/t.at(0)+(n%t.at(0)==0?4:5) << endl;
  return 0;
}

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
// #define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    string s, t; cin >> s >> t;
    int res = 0;
    rep(i, 3) if(s[i] == t[i]) res++;
    cout << res << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 7708
'use strict'

const Main = input => {
  const row_list = input.split('\n');
  const row0_sp = row_list[0].split(' ');
  const N = row0_sp[0]; const M = row0_sp[1];
  let sum = 0;
  const items = row_list[1].split(' ').map(item => {
    const num = Number(item);
    sum += num;
    return num;
  });
  items.sort((a, b) => b - a);
  
  const border = sum / (4 * M);

  let canSelect = true;
  for(let i = 0; i < M; i++) {
    if(items[i] < border) {
      canSelect = false;
      break;
    }
  }

  console.log(canSelect ? 'Yes' : 'No');
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7500
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<P> lr(n);
    rep(i, n) cin >> lr[i];

    sort(all(lr));
    int ans = 0;
    vi mil(n+1, INT_MAX), mir(n+1, INT_MAX);
    rep(i, n) {
        mil[i+1] = min(mil[i], lr[i].second);
        mir[n-1-i] = min(mir[n-i], lr[n-1-i].second);
    }

    int min = INT_MAX;
    rep(i, n-1) {
        chmin(min, lr[i].second);
        if(min < lr[i].first) break;
        chmax(ans, min-lr[i].first + mir[i+1]-lr[n-1].first + 2);
    }
    rep(i, n) {
        chmax(ans, lr[i].second - lr[i].first + 1 + (mil[n] >= lr[n-1].first?mil[n]-lr[n-1].first+1:0));
    }

    cout << ans << endl;
}

Measured memory_bytes: 4768
import sys
input = sys.stdin.buffer.readline
input = sys.stdin.readline


# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
#import numpy as np

def main():
	n,k=map(int,input().split())
	x=list(map(int,input().split()))

	ans=10**18

	for i in range(n):
		try:
			l=x[i]
			r=x[i+k-1]
			if r<0:
				ans=min(ans,-l)
			elif l>0:
				ans=min(ans,r)
			else:
				ans=min(ans,r-l+min(-l,r))
		except:
			pass
	print(ans)



if __name__ == "__main__":
	main()


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

using namespace std;

const int N = 1000010;

char s[N];
int n, a[N], b[N];

// int brute() {
//   int m = n;
//   for (int i = 1; i <= m; ++i) b[i] = a[i];
//   while (m > 1) {
//     for (int i = 1; i < m; ++i) b[i] = abs(b[i] - b[i + 1]);
//     --m;
//   }
//   return b[1];
// }

int main() {
  scanf("%d %s", &n, s + 1); --n;
  bool isOne = 0;
  for (int i = 1; i <= n; ++i) {
    a[i] = abs(s[i] - s[i + 1]);
    if (a[i] == 1) isOne = 1;
  }
  // cout << brute() << " ";
  int fac = 1;
  if (!isOne) {
    for (int i = 1; i <= n; ++i) a[i] >>= 1;
    fac = 2;
  } 
  int sum = 0;
  for (int i = 1; i <= n; ++i) {
    if ((i - 1) & (n - i)) continue;
    sum += (a[i] & 1), sum &= 1;
  }
  cout << sum * fac << '\n';
  return 0;
}



Measured memory_bytes: 7040
def gcd(a: int, b: int) -> int:
    """a, bの最大公約数(greatest common divisor: GCD)を求める
    計算量: O(log(min(a, b)))
    """
    if b == 0:
        return a
    return gcd(b, a%b)


class Ruiseki_lr:
    """左右からの畳み込みをそれぞれ計算する"""
    def __init__(self, array, op, e):
        self.op = op
        self.e = e

        n = len(array)
        self.left = [e] * (n + 1)
        self.right = [e] * (n + 1)
        for i in range(n):
            self.left[i + 1] = self.op(self.left[i], array[i])
        for i in reversed(range(n)):
            self.right[i] = self.op(self.right[i + 1], array[i])

    def left(self, p):
        """区間[0, p)の畳み込み結果を返す"""
        return self.left[p]

    def right(self, p):
        """区間[p, n)の畳み込み結果を返す"""
        return self.right[p]

    def fold(self, p):
        """p番目を除いた区間[0, n)の畳み込み結果を返す"""
        return self.op(self.left[p], self.right[p + 1])

n = int(input())
a = list(map(int, input().split()))

ru = Ruiseki_lr(a, gcd, 0)
max_ = 0
for i in range(n):
    max_ = max(ru.fold(i), max_)
print(max_)

Measured memory_bytes: 63984
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

#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 Rep(i, n) for (long long i = 0; i< (long long)(n); i++)
#define RRep(i,n) for (long long i = ((long long)(n)-1); i>=0; i--)
#define all(v) (v).begin(),(v).end()

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    int weight;
    edge(int f,int t,int w) : from(f), to(t), weight(w){ }
};

using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

template <class T>
inline bool chmin(T &a, T b){
    if (a > b){
        a = b;
        return true;
    }
    return false;
}

template <class T>
inline bool chmax(T &a, T b){
    if (a < b){
        a = b;
        return true;
    }
    return false;
}

template <class T>
T gcd(T a, T b){
    if( b==0 ) return a;
    return gcd(b, a%b);
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

int INF = 1e9+7;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

int main(){
    ll a,b,c;
    cin >> a >> b >> c;
    ll x = c-a-b;
    if(x<=0){
        cout << "No" << endl;
        return 0;
    }
    ll y = 4*a*b;
    if(y<x*x) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long LL;

int main(){
  int N;
  cin >> N;
  vector<double> T(N), V(N), dist(101, -1);
  dist[0] = 0;
  REP(i, N) { cin >> T[i]; }
  REP(i, N) { cin >> V[i]; }
  REP(i, N) {
    REP(j, T[i]) {
      vector<double> ndist(101, -1);
      REP(ps, V[i]+1) {
        for(int s = ps-1; s <= ps+1; ++s) {
          if(s < 0 || s > V[i] || dist[s] < 0) continue;
          double tdist = dist[s] + (s + ps) * 0.5 + (s == ps && s < V[i] ? 0.25 : 0);
          ndist[ps] = max(tdist, ndist[ps]);
        }
      }
      dist = ndist;
    }
  }
  cout << fixed << setprecision(9) << dist[0] << endl;
}

Measured memory_bytes: 384
#include <stdio.h>

long long a, b;

long long gcd(long long a, long long b) {
    return (b ? gcd(b, a % b) : a);
}

long long lcm(long long a, long long b) {
    return (a * b) / gcd(a, b);
}

int main() {
    scanf("%d%d", &a, &b);
    printf("%lld\n", lcm(a, b));
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) throws Exception {
		while (true) {
			int N = sc.nextInt();
			if (N == 0) break;
			int a = 0;
			int b = 0;
			for (int i = 0; i < N; ++i) {
				int ac = sc.nextInt();
				int bc = sc.nextInt();
				if (ac < bc) {
					b += ac + bc;
				} else if (ac > bc) {
					a += ac + bc;
				} else {
					a += ac;
					b += bc;
				}
			}
			System.out.println(a + " " + b);
		}
	}

}

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

int main(){
    int a, b, c, d;

    cin >> a >> b >> c >> d;

    if(b <= c || d <= a){
        printf("0\n");
    }
    else{

    if(a <= c and b <= d){
        printf("%d\n", b - c);
    }
    else if(c <= a and b <= d){
        printf("%d\n", b - a);
    }
    else if(c <= a and d <= b){
        printf("%d\n", d - a);
    }
    else if( a <= c and d <= b){
        printf("%d\n", d - c);
    }
    }
    

    return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

int main(){
    ll h,w; cin >> h >> w;
    string s[h];
    rep(i,h)cin >> s[i];
    ll dx[4] = {0,0,1,-1};
    ll dy[4] = {1,-1,0,0};
    bool ok = true;
    rep(i,h)rep(j,w){
        if(s[i][j] == '#'){
            bool temp = false;
            rep(k,4){
                ll nx = i + dx[k];
                ll ny = j + dy[k];
                if(0 <= nx && nx < h && 0 <= ny && ny < w){
                    temp |= s[nx][ny] == '#';
                }
            }
            ok &= temp;
        }
    }
    cout << (ok ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.buffer.readline
n = int(readline())
ab = [[0,0] for i in range(n)]
lsta = list(map(int,input().split()))
lstb = list(map(int,input().split()))
for i in range(n):
    ab[i][0] = lsta[i]
    ab[i][1] = lstb[i]

bstock = 0

move = sum(lstb) - sum(lsta)

if move == 0:
    if lsta == lstb:
        print("Yes")
    else:
        print("No")
    exit()

ab.sort()
i = 0
while i < n-1:
    if ab[i][0] > ab[i][1]: #bstockを使う
        if ab[i][0] > ab[i][1]+bstock:
            print("No")
            exit()
        else:
            bstock -= ab[i][0]-ab[i][1]
    elif ab[i][0]%2 == ab[i][1]%2:
        bstock += (ab[i][1]-ab[i][0])//2
        move -= (ab[i][1]-ab[i][0])//2
    else:
        move -= (ab[i][1]-ab[i][0])//2 + 1
        bstock += (ab[i][1]-ab[i][0])//2
    if move < 0 or bstock < 0:
        print("No")
        exit()    
    i+= 1

if ab[-1][0]+(move*2)==ab[-1][1]+move+bstock:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 42480
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,N) for(int i = 0;i < (int)(N);i++)
int main(){
  string s;
  cin>>s;
  int x=0;
  int n=s.size();
  rep(i,n){
      if(s[i]!=s[n-1-i]){
        x++;
      }
    }
  cout<<x/2<<endl;  
}



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

const int EMPTY = -1;
const int WALL = -2;

int map[1001][1001];

bool isnear[1001][1001] = {false};
vector< vector<int> > graph;

bool visited[500001] = {false};

int warps[20][2] = {
    {-2, -2}, {-2, -1}, {-2, 0}, {-2, 1}, {-2, 2},
    {-1, -2}, {-1, -1}, {-1, 1}, {-1, 2},
    {0, -2}, {0, 2},
    {1, -2}, {1, -1}, {1, 1}, {1, 2},
    {2, -2}, {2, -1}, {2, 0}, {2, 1}, {2, 2}
};

struct state {
    int now;
    int cost;
    state(int n, int c) : now(n), cost(c) {};
};

int H, W; 
bool placeable(int y, int x) {
    return (y>=0 && y<H && x>=0 && x<W);
}

void dfs(int y, int x, int num, set<int>& near) {
    if (!placeable(y, x)) return;
    if (map[y][x] != EMPTY) return;
    map[y][x] = num;
    for (int i=0; i<20; i++) {
        const int yy = y+warps[i][0];
        const int xx = x+warps[i][1];
        if (placeable(yy, xx))
            if (map[yy][xx] != num && map[yy][xx] >= 0) {
                near.insert(map[yy][xx]);
            }
    }
    dfs(y, x+1, num, near);
    dfs(y, x-1, num, near);
    dfs(y+1, x, num, near);
    dfs(y-1, x, num, near);
}

int main() {
    cin>>H>>W;
    int y, x; cin>>y>>x;
    y--; x--;
    int dy, dx; cin>>dy>>dx;
    dy--; dx--;
    for (int i=0; i<H; i++) {
        string tmp; cin>>tmp;
        for (int j=0; j<W; j++) {
            map[i][j] = (tmp.at(j)=='#'?WALL:EMPTY);
        }
    }
    // Numbering areas, store near areas to vector
    int nodes = 0;
    graph.resize(500001);
    for (int y=0; y<H; y++) {
        for (int x=0; x<W; x++) {
            if (map[y][x] == EMPTY) {
                set<int> near;
                dfs(y, x, nodes, near);
                for (auto it=near.begin(); it!=near.end(); it++) {
                    graph[nodes].push_back(*it);
                    graph[*it].push_back(nodes);
                }
                nodes+=1;
            }
        }
    }
    queue<state> Q;
    Q.push(state(map[y][x], 0));
    int dest = map[dy][dx];
    while(!Q.empty()) {
        int now = Q.front().now;
        int cost = Q.front().cost;
        Q.pop();
        if (visited[now]) continue;
        if (now == dest) {
            cout<<cost<<endl;
            return 0;
        }
        visited[now] = true;
        for (int next: graph[now]) {
            Q.push(state(next, cost+1));
        }
    }
    cout<< -1 <<endl;
}

Measured memory_bytes: 23636