akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
inline void read(ll &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const ll inf = 6e18;
ll a[4],n,res=inf;
ll solve(ll n, int S){
	assert((S>>2&1)&&(S>>3&1));
	ll res=0;
	/*if(S>>3&1)res+=n/8*a[3],n%=8;
	if(S>>2&1)res+=n/4*a[2],n%=4;
	if(S>>1&1)res+=n/2*a[1],n%=2;
	if(S>>0&1)res+=n/1*a[0],n%=1;*/
	res+=n/8*a[3],n%=8;res+=n/4*a[2],n%=4;
	assert(!n);return n==0?res:inf;
}
int main() {
	rep(i,0,3)read(a[i]);rep(i,1,3)a[i]=min(a[i],a[i-1]*2);
	read(n);
	n*=4;
	cout<<solve(n,15);
	return 0;
}

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

// #define TEST_CASES
using ll = long long;
#define ff first
#define ss second
const int N = 1e5 + 10;

int n;
int a[N];

void solve()
{
	cin>>n;
	for (int i = 0; i < n; i++)
		cin>>a[i];
	sort(a, a + n);
	int p = 0;
	int ans = 0;
	for (int i = 0; p < n and i < N; i++)
	{
		while(p < n and a[p] < i) p++;
		if (n - p == p) ans++; 
		if (p > n - p) break;
	}
	cout<<ans<<endl;
}

int main()
{
	int t = 1;
#ifdef TEST_CASES
	cin>>t;
#endif
	while(t--)
	{
		solve();
	}
}



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

int main() {
	int a, b,c;
	cin >> a>>b;
	if (b < 10)
		c = 10 * a + b;
	else if (b < 100)
		c = 100 * a + b;
	else c = 1000 * a + b;
	for (int i = 0;i < 10001;i++)
	{
		if (c == i * i)
		{
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";
	return 0;

}


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

int main(){
    int a, b;
    cin >> a >> b;
    int small = min(a, b);
    int big = max(a, b);
    for (int i = 0; i < big; i++){
        cout << small;
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <complex>
#include <queue>
#define repi(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) repi(i, 0, n)
#define endl "\n"
#define ing long long
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }
int n, m;
struct edge
{
    int to, cost;
    edge(int to, int cost) : to(to), cost(cost) {}
};
vector<edge> G[500];
int solve(int s)
{
    vector<int> dist(n, 0);
    using P = pair<int, int>;
    //intpriority_queue<P, vector<P>, greater<P>> que;
    priority_queue<P> que;
    que.push(P(0, 0));
    dist[0] = 0;
    while(que.size())
    {
        P p = que.top(); que.pop();
        int v = p.second;
        for(auto &u : G[v])
        {
            if(p.first + u.cost > dist[u.to])
            {
                dist[u.to] = p.first + u.cost;
                que.push(P(dist[u.to], u.to));
            }
        }
    }
    return dist[n - 1];
}
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    for(int i = 0; i < m; i++)
    {
        int s, t, c; cin >> s >> t >> c;
        G[s].emplace_back(t, c);
    }
    cout << solve(0) << endl;
    return 0;
}



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

int main()
{
  int H,W,N ;
  cin>>H>>W>>N ;
  
  int ans=(N%(H>W?H:W)) ;
  cout<<(ans==0?N/(H>W?H:W):N/(H>W?H:W)+1)<<endl ;
  
  return 0 ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 998244353;
const ll INF = 1e18;
#define REP(i,n) for(int i=0;i<n;i++)
#define ALL(v) v.begin(),v.end()

struct unionfind {
	vector<int> par, siz;
	unionfind(int N) : par(N), siz(N,1) {
		for (int i=0;i<N;i++) par[i]=i;
	}
	int root(int x) {
		while(par[x]!=x) x=par[x]=par[par[x]];
		return x;
	}
	void unite(int x, int y) {
		x=root(x); y=root(y);
		if (x==y) return;
		if (siz[x]<siz[y]) swap(x,y);
		siz[x]+=siz[y];
		par[y]=x;
	}
	bool same(int x, int y) {
		return root(x)==root(y);
	}
	int size(int x) {
		return siz[root(x)];
	}
};

int main(){
	int n, m; cin >> n >> m;
	unionfind uf(n);
	int a, b;
	REP(i,m){
		cin >> a >> b;
		a--; b--;
		uf.unite(a,b);
	}
	set<int> st;
	REP(i,n){
		st.insert(uf.root(i));
	}
	cout << st.size()-1 << endl;
	return 0;
}

Measured memory_bytes: 7988
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define INF (ll)(1e18)
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }




void solve() {
    string s, t;
    cin >> s >> t;
    
    int id = -1;
    rep(i, sz(s) - sz(t) + 1) {
        rep(j, sz(t)) {
            if (!(s[i + j] == '?' || s[i + j] == t[j])) break;
            
            if (j == sz(t) - 1) {
                id = i;
            }
        }
    }
    if (id == -1) { cout << "UNRESTORABLE" << endl; return; }
    
    rep3(j, id, id + sz(t)) {
        s[j] = t[j - id];
    }
    rep(i, sz(s)) if (s[i] == '?') s[i] = 'a';
    cout << s << endl;
    
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int T;
    // cin >> T;
    T = 1;
    
    while (T--) {
        solve();
    }
}





Measured memory_bytes: 256
import scala.annotation.tailrec
import scala.io.StdIn._
object Main extends App{


  val Array(n, m) = readLine.trim.split(' ').map(_.toInt)
  val cards = readLine.trim.split(' ').map(_.toLong).sorted
  val op = Array.tabulate(m){_ ⇒
    val Array(b, c) = readLine.trim.split(' ').map(_.toInt)
    (b, c.toLong)
  }.sortBy(_._2)(Ordering.Long.reverse)
  var left = 0

  var sum = 0L

  for ((b, c) ← op) {
    val right = lowerBound(cards, left, c)
    if (right - left > b) {
      left += b
      sum += b * c
    }else {
      sum += (right - left) * c
      left = right
    }
  }
  println(sum + (left until cards.size).map{i ⇒ cards(i)}.sum)








  def lowerBound(array: Array[Long], from: Int, target: Long): Int = {
    var left = from
    var right = array.size
    while(left < right){
      val mid = (left + right) / 2
      if (array(mid) < target) {
        left = mid + 1
      }else {
        right = mid
      }
    }
    right
  }
}

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

#define long long long

using namespace std;

const int N = 3e3+5;
const int M = 998244353;

int n, s, A[N];
long dp[N][N][2];

long solve(int idx, int sum, int f) {
    if(sum == s) return n - idx + 1;
    if(idx == n) return 0;
    long &now = dp[idx][sum][f];
    if(~now) return now;
    now = 0;
    now = (now + solve(idx + 1, sum, f)) % M;
    if(sum + A[idx + 1] <= s) now = (now + solve(idx + 1, sum + A[idx + 1], 1)) % M;
    return now;
}

int main() {
    memset(dp, -1, sizeof dp);

    scanf("%d %d", &n, &s);
    for(int i = 1; i <= n; i++) scanf("%d", A + i);
    solve(0, 0, 0);
    long ans = 0;
    for(int i = 1; i <= n; i++) if(A[i] <= s)
        ans = (ans + solve(i, A[i], 1) * i % M) % M;
    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 141440
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

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

  int count = 0;
  rep(i, N)
  {
    if (i * (i + 1) / 2 >= N)
    {
      count = i;
      break;
    }
  }

  while (N != 0)
  {
    if (N != 1 && N != 2)
    {
      N -= count;
      cout << count << endl;
      count--;
    }

    if (N == 1 || N == 2 || N <= count)
    {
      cout << N << endl;
      N = 0;
    }
  }

  return 0;
}

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



int main() {
string S;
cin >> S;
int lon = S.size();
int ans = 1000;
for(int i = 0; i+2 < lon; i++){
string kari = S.substr(i, 3);
int keke = stoi(kari);
if(keke > 753)keke -= 753;
else keke = 753 - keke;
ans = min(ans, keke);


}
cout << ans << endl;
}

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

int main(){
    int n, m, cnt=0; cin >> n >> m;
    vector<int> p(m);
    vector<vector<int> > lamp(n); //スイッチ i につながる電球
    for(int i = 0; i < m; i++){
        int k; cin >> k;
        for(int j = 0; j < k; j++){
            int s; cin >> s;
            lamp[s-1].push_back(i);
        }
    }
    for(int i = 0; i < m; i++) cin >> p[i];
    
    for(int i = 0; i < (1<<n); i++){ //2のn乗まで
        bool allOn = true; //各組み合わせで全電球ON?
        vector<int> sw(m); //  電球jにつながるOnのスイッチ  
        int comb = i;
        for(int j = 0; j < n; j++){
            if(comb%2){ //i=combをビットごとに抽出
                for(int l = 0; l < lamp[j].size(); l++) sw[lamp[j][l]]++;
                
            }
            comb /= 2;
        }
        for(int j = 0; j < m; j++){
            if((sw[j]%2)!=p[j]) allOn = false;
        }
        if(allOn) cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
using ll = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b)a=b;};
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b)a=b;};

namespace Geometry{

  typedef long double D;
  typedef complex<long double> P;
  typedef pair<P, D> C;

  const D EPS = 1e-9;
  const D PI = asin(1) * 2;
  const D INF = 1e18;
  //area, cross, 
  D dot(P p1, P p2){
    return p1.real() * p2.real() + p1.imag() * p2.imag();
  }

  D cross(P p1, P p2){
    return p1.real() * p2.imag() - p1.imag() * p2.real();
  }

  D area(const vector<P> poly){
    D ans = 0;
    for(int i=2;i<(int)poly.size();i++)
      ans += cross(poly[i-1] - poly[0], poly[i] - poly[0]);
    return abs(ans)/2;
  }
  

};


using namespace Geometry;

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  ll r,x,y,n;
  cin>>r>>x>>y>>n;
  P C(x,y); C/=P(0,1); C=conj(C);
  vector<ll> A(n);
  vector<ll> B(n);
  ll sum=0;
  for(auto &I:A){cin>>I; sum+=I;}
  B[0]=A[0];
  for(int i=1;i<n;i++){B[i]=B[i-1]+A[i];}
  vector<D> a(n);
  for(int i=0;i<n;i++){a[i]=PI*A[i]/sum*r*r;}
  vector<D> b(n);
  //cout<<C<<endl;
  for(int i=0;i<n;i++){
    b[i]=PI*A[i]/sum*r*r;
    P lf=polar((D)r,(D)(i==0?0LL:B[i-1])/sum*2*PI);
    P rg=polar((D)r,(D)B[i]/sum*2*PI);
    b[i]-=cross(lf,rg)/2;
    b[i]+=cross(lf-C,rg-C)/2;
    //cout<<i<<" "<<lf<<" "<<rg<<endl;
    //cout<<a[i]<<" "<<b[i]<<endl;
    //cout<<cross(lf,rg)/2<<" "<<cross(lf-C,rg-C)/2<<endl;
  }
  for(int i=0;i<n;i++){
    cout<<(ll)(b[i]/a[i]*100);
    if(i+1!=n){cout<<" ";}
  }
  cout<<endl;
  
  return 0;
}



Measured memory_bytes: 3528
#include<bits/stdc++.h>
typedef long long LL;
using namespace std;
const int N=19;
int n,a[N];
struct sta {
	int l,r,xl,xr;
};
bool operator < (sta A,sta B) {
	if(A.l != B.l) return A.l<B.l;
	if(A.r != B.r) return A.r<B.r;
	if(A.xl != B.xl) return A.xl<B.xl;
	return A.xr<B.xr;
}
map<sta,LL> Map;
LL solve(int l,int r,int xl,int xr) {
	if(l >= r-1) return 0;
	if(Map.count((sta){l,r,xl,xr})) return Map[(sta){l,r,xl,xr}];
	LL res=1e12;
	for(int i=l+1;i<r;++i)
		res=min(res,(LL)(xl+xr)*a[i]+solve(l,i,xl,xl+xr)+solve(i,r,xl+xr,xr));
	return Map[(sta){l,r,xl,xr}]=res;
}
int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
		scanf("%d",&a[i]);
	cout<<solve(1,n,1,1)+a[1]+a[n]<<endl;
	return 0;
}

Measured memory_bytes: 20044
function Main(input) {
  var tmp = input.split("\n");
  tmp.shift();
  var left = 1;
  var right = 10000000;
  
  for(var i = 0; i < tmp.length; i++){
    var tmp2 = tmp[i].split(" ").map((tmp)=>Number(tmp));
    if(tmp2[0] > left){
       left = tmp2[0];
    }
    if(tmp2[1] < right){
       right = tmp2[1];
    }
  }
  
  console.log(Math.max((right - left + 1),0));
}

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


Measured memory_bytes: 29072
n,m,l = gets.split.map {|s| s.to_i}
a = Array.new
b = Array.new
for i in 1..n
  c = gets.split.map {|s| s.to_i}
  a.push(c)
end
for j in 1..m
  c = gets.split.map {|s| s.to_i}
  b.push(c)
end
for i in 1..n
  for j in 1..l
    print " " unless j == 1
    s = 0
    for k in 1..m
      s += a[i-1][k-1] * b[k-1][j-1]
    end
    print s
  end
  print "\n"
end


Measured memory_bytes: 7120
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const ll INF = (1LL << 31) - 1;
const ll MOD = 1e9 + 7;

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


/******************************************************************************************/


int main() {

	int n;
	cin >> n;
	vector<int> a(n);
	int sum = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		sum += a[i];
	}
	sort(a.begin(), a.end());
	if ((sum % 10) != 0) {
		cout << sum << endl;
		return 0;
	}

	for (int i = 0; i < n; i++)
	{
		if (a[i] % 10) {
			cout << sum - a[i] << endl;
			return 0;
		}
	}

	cout << "0" << endl;
	
	

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long


const int N = 2e5+5;
int n,m;
int fact[101]={0};
bool isPalin(string s){
	string str= s;
	reverse(str.begin(), str.end());
	if(str==s)
		return true;
	return false;
}

int32_t main()
{
	IOS;
	string s;
	cin>>s;
	int n=s.length();
	string s1, s2;
	s1= s.substr(0, (n-1)/2);
	s2= s.substr(((n+3)/2)-1, (n)- (n+3)/2  +1);
	//cout<<s1<<" "<<s2;
	if(isPalin(s) && isPalin(s1) && isPalin(s2))
		cout<<"Yes"<<endl;
	else 
		cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
#include <utility>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
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 int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.exe
int digit(int a){
    int count = 0;
    for (int i = 0; i < a; i++)
    {   if (a == 0)
        {
            break;
        }else
        {
            a = a/10;
            count++;
        }     
    }
    return count;
}
//pow(x,n) == x^n

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

int n;
cin >> n;
vector <int> a(n);
rep(i,n) cin >> a[i];
Sort(a);
cout << a[n-1]-a[0] << endl;


//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
typedef long long ll;
typedef long l;
typedef pair<int,int> p;
typedef vector<int> ve;
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(int i=a;i<b;i++)
int height[100001]={};
int cost[100001]={};
int dp(int current,int n)
{
  if(current==n)
    return 0;
  if(cost[current]!=INT_MAX)
    return cost[current];
  if(current+1==n)
  {
    return cost[current]=abs(height[current]-height[current+1]);
  }
  if(current+2<=n)
  {
    return cost[current]=min(abs(height[current]-height[current+1])+dp(current+1,n),abs(height[current]-height[current+2])+dp(current+2,n));
  }
}
int main()
{
  //start here
  int n;
  cin>>n;
  loop(i,1,n+1)
  {
    cin>>height[i];
  }
  fill(cost,cost+n,INT_MAX);
  int ans=dp(1,n);
  cout<<cost[1];
  return 0;
}

Measured memory_bytes: 3328
n,k,q=gets.split.map(&:to_i)
a=Array.new(n,0)
b=0
q.times do |i|
    a[gets.to_i-1]+=1
end

n.times do |i|
    if k-q+a[i]>0
        puts "Yes"
    else
        puts "No"
    end
end


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

int main(){
    long long n, cnt=0;
    cin >> n;
    vector<int> a(n+1), b(n);
    for(int i = 0; i <= n; i++) cin >> a[i];
    for(int i = 0; i < n; i++){
        cin >> b[i];
        int beat1 = min(a[i], b[i]);
        cnt += beat1; b[i] -= beat1; a[i] -= beat1;
        int beat2 = min(a[i+1], b[i]);
        cnt += beat2; b[i] -= beat2; a[i+1] -= beat2;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<vector>
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
const int N=1e6+5;
template<class T>inline void read(T &res)
{
char c;T flag=1;
while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
}
string s;
int dp[N][2];
int main(){
	cin>>s;
	dp[0][1]=1;
	int n=s.size();
	for(int i=0;i<n;i++){
		int x=s[i]-'0';
		dp[i+1][0]=min(dp[i][0]+x,dp[i][1]+10-x);
		dp[i+1][1]=INF;
		if(x<9)dp[i+1][1]=min(dp[i+1][1],dp[i][0]+x+1);
		if(x)dp[i+1][1]=min(dp[i+1][1],dp[i][1]+9-x);
	}
	cout<<dp[n][0]<<endl;;
	return 0;
}


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

int main() {
	int A;
  int B;
  cin >> A;
  cin >> B;
  if(A+B>A+A-1 && A+B>B+B-1){
    cout << A+B;
  }else if(A+A-1>B+B-1){
    cout << A+A-1;
  }else{
    cout << B+B-1;
  }
	return 0;
}


Measured memory_bytes: 3600
N, X = [int(_) for _ in input().split()]

A = [1]
for i in range(N):
    A.append(A[-1] * 2 + 3)
P = [1]
for i in range(N):
    P.append(2 * P[-1] + 1)


def f(n, x):
    if n <= 0 and x == 1: return 1
    if x == 1: return 0
    if x <= A[n - 1] + 1:
        return f(n - 1, x - 1)
    if A[n - 1] + 2 == x:
        return P[n - 1] + 1
    if 2 * A[n - 1] + 3 > x:
        return P[n - 1] + 1 + f(n - 1, x - A[n - 1] - 2)
    else:
        return 2 * P[n - 1] + 1


print(f(N, X))


Measured memory_bytes: 3064
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#pragma endregion

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);

  string s;
  cin >> s;
  int n = s.length();
  ll a[500010] = {};
  ll cnt = 0;
  rep(i, n)
  {
    if (s[i] == '<')
    {
      cnt++;
    }
    else
    {
      cnt = 0;
    }
    a[i + 1] = max(a[i + 1], cnt);
  }

  for (int i = n; i >= 0; --i)
  {
    if (s[i - 1] == '>')
    {
      cnt++;
    }
    else
    {
      cnt = 0;
    }
    a[i - 1] = max(a[i - 1], cnt);
  }
  ll sum = 0;
  rep(i, n + 1) sum += a[i];
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 4764
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <string>

using namespace std;

#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 (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define debug(x) cout<<#x<<": "<<x<<endl
#define MOD 1000000007

typedef long long ll;
typedef unsigned long long ull;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

int main(void)
{
    const int MAX_N = 100000;
    ll N, L;
    ll a[MAX_N];
    cin >> N >> L;
    REP(i, N) {
        cin >> a[i];
    }
    bool flag = false;
    int x = -1;
    REP(i, N - 1) {
        if (a[i] + a[i + 1] >= L) {
            flag = true;
            x = i;
        }
    }
    if (flag) {
        cout << "Possible" << endl;
        FOR(i, 0, x) {
            cout << i + 1 << endl;
        }
        RFOR(i, x + 1, N - 1) {
            cout << i + 1 << endl;
        }
        cout << x + 1 << endl;
    } else {
        cout << "Impossible" << endl;
    }
    return 0;
}

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int N;
ll A[200005];
ll B[200005];
ll C[200005];
ll D[35];

//! under以上になる最小のindex
ll getUnder(ll under)
{
    if (under <= 0)
        return 0;
    ll ok = N, ng = -1;
    while (abs(ok - ng) > 1)
    {
        int mid = (ok + ng) / 2;
        if (C[mid] >= under)
        {
            ok = mid;
        }
        else
        {
            ng = mid;
        }
    }
    return ok;
}
//! top未満になる最大のindex
ll getTop(ll top)
{
    ll ok = -1, ng = N;
    while (abs(ok - ng) > 1)
    {
        int mid = (ok + ng) / 2;
        if (C[mid] < top)
        {
            ok = mid;
        }
        else
        {
            ng = mid;
        }
    }
    return ok;
}

int main()
{
    cin >> N;
    REP(i, N)
    {
        cin >> A[i];
    }
    REP(i, N)
    {
        cin >> B[i];
    }
    ll ans = 0;
    ll bit = 1;
    REP(i, 29)
    {
        D[i] = 0;
        bit <<= 1;
        REP(j, N)
        {
            C[j] = (B[j] % bit);
        }
        sort(C, C + N);
        ll t = (bit >> 1);
        REP(j, N)
        {
            ll a = A[j] % bit;
            {
                ll ui = getUnder(t - a);
                ll ti = getTop(2 * t - a);
                if (ui <= ti)
                {
                    D[i] += (ti - ui + 1);
                }
            }
            {
                ll ui = getUnder(3 * t - a);
                ll ti = getTop(4 * t - a);
                if (ui <= ti)
                {
                    D[i] += (ti - ui + 1);
                }
            }
        }
        ans |= ((D[i] % 2) << i);
    }

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

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
const ll MOD = 998244353;
ll dp[4010][4010];
ll cntr[4010];
ll cntb[4010];

int main() {
    string S;
    cin >> S;
    dp[0][0] = 1;
    for(ll i = 0; i < S.size(); i++){
        char c = S[i];
        cntr[i + 1] = cntr[i] + 2 * (c == '0') + (c == '1'); 
        cntb[i + 1] = cntb[i] + 2 * (c == '2') + (c == '1');
    }
    for(ll i = S.size(); i < 4010; i++){
        cntr[i + 1] = cntr[i];
        cntb[i + 1] = cntb[i];
    }
    for(ll i = 1; i <= 2 * S.size(); i++){
        for(ll r = 0; r <= min(i, cntr[i]); r++){
            ll b = i - r;
            if(b > cntb[i]) continue;
            if(r > 0) dp[r][b] += dp[r - 1][b];
            if(b > 0) dp[r][b] += dp[r][b - 1];
            dp[r][b] %= MOD;
        }
    }
    cout << dp[cntr[4010 - 1]][cntb[4010 - 1]] << endl;
    return 0;
}


Measured memory_bytes: 123520
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;

/*
*/

ll n,a[100010],ru[100010],ru2[100010],ans=1;

long long gcd(long long a,long long b){
	if(b==0)return a;
	return gcd(b,a%b);
}

void init(){
	cin>>n;
	reg(i,1,n)cin>>a[i];
	ru[0]=0;
	ru[1]=a[1];
	reg(i,2,n)ru[i]=gcd(a[i],ru[i-1]);
	ru2[n+1]=0;
	ru2[n]=a[n];
	ireg(i,1,n-1)ru2[i]=gcd(a[i],ru2[i+1]);
}

int main(void){
	init();
	reg(i,1,n){//抜くやつ
		ans=max(ans,gcd(ru[i-1],ru2[i+1]));
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2560
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.Ia;
		var a=sc.La;
		var b=sc.La;
		double p1=0,p2=0;
		var g=new double[4];
		for(int i = 0;i<4;i++) {
			p1+=s[i&1]*a[i&1];
			p2+=s[i&1]*b[i&1];
			g[i]=p1-p2;
		}
		if(g[0]==g[2]||g[1]==g[3]){
			Console.WriteLine("infinity");
			return;
		}
		if((0<g[0]&&g[0]<g[1])||(0>g[0]&&g[0]>g[1])){
			Console.WriteLine(0);
			return;
		}
		BigInteger n=(BigInteger)Sqrt(double.MaxValue-1);
		BigInteger lb=0,ub=n-1,mid=0;
		while(ub-lb>1){
			mid=(ub+lb)/2;
			var z1=mid*s[0]*a[0]+(mid-1)*s[1]*a[1];
			var z2=mid*s[0]*b[0]+(mid-1)*s[1]*b[1];
			if(z1==z2){
				Console.WriteLine((mid-1)*2);
				return;
			}
			if((z1<z2)==(z1+s[1]*a[1]<z2+s[1]*b[1])){ub=mid;}
			else{lb=mid;}
		}
		Console.WriteLine("{0}",Max(0,(long)(lb-1)*2+1+((lb+1)*s[0]*a[0]+lb*s[1]*a[1]==(lb+1)*s[0]*b[0]+lb*s[1]*b[1]?1:0)));
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 13524
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int W, H, x, y; cin >> W >> H >> x >> y;
    double ans = (double)W * H / 2.0;
    int f = 0;
    if(W == 2 * x && H == 2 * y) f = 1;
    cout << ans << " " << f << endl; 


    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

#define M_PI       3.14159265358979323846

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

bool solve()
{
    int N;

    cin >> N;

    vector<int> vh = fetch_vec<int>(N);

    vh[0]--;

    for (int i = 1; i < N; ++i)
    {
        if (vh[i] > vh[i - 1])
            vh[i]--;
        else if (vh[i] < vh[i-1])
            return false;

    }

    return true;
}

int main()
{
    if (solve())
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 640
import java.io.*
import java.util.*

fun solve(N: Long, i: Long) {
    println(N - i + 1)
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }

    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }

    val sc = Scanner(System.`in`)
    val N = sc.next().toLong()
    val i = sc.next().toLong()
    solve(N, i)
}



Measured memory_bytes: 31396
//  Created by Sengxian on 2017/5/27.
//  Copyright (c) 2017年 Sengxian. All rights reserved.
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int main() {
	ll n, a, b;
	cin >> n >> a >> b;
	if (a > b) return puts("0"), 0;
	if (n == 1 && a != b) return puts("0"), 0;
	if (n == 1) return puts("1"), 0;
	printf("%lld\n", (b * (n - 2) - a * (n - 2)) + 1);
	return 0;
}


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

using namespace std;
using ll=long long;
int a[20];

ll dp(int l, int r, ll x, ll y) {
    if (l > r) return 0;
    if (l == r) return (x+y) * a[l];
    ll mi = 1ll<<62;
    for (int m = l; m <= r; m++) {
        mi = min(mi, dp(l, m-1, x, x+y) + dp(m+1, r, x+y, y) + (x+y)*a[m]);
    }
    return mi;
}
void solve() {
    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    cout << dp(1, n-2, 1, 1) + a[0] + a[n-1];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 384
import sys


input = sys.stdin.readline


def main():
    N, Q = map(int, input().split())
    lst_ab = [tuple(map(int, input().split())) for i in range(N - 1)]
    lst_px = [tuple(map(int, input().split())) for i in range(Q)]

    tree = [[] for _ in range(N)]
    for a, b in lst_ab:
        a -= 1
        b -= 1
        tree[a].append(b)
        tree[b].append(a)

    lst_score = [0] * N
    for p, x in lst_px:
        p -= 1
        lst_score[p] += x

    lst_ans = [0] * N
    lst_ans[0] = lst_score[0]
    lst_visited = [0] * N
    stack = [0]
    while stack:
        v = stack.pop()
        lst_visited[v] = 1
        for to in tree[v]:
            if lst_visited[to]:
                continue
            stack.append(to)
            lst_ans[to] = lst_ans[v] + lst_score[to]
    
    print(*lst_ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 116376
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {
	private	static	BufferedReader	br = null;

	static {
		br = new BufferedReader(new InputStreamReader(System.in));
	}
 
    /**
     * @param args
     */
	public static void main(String[] args) {
	// TODO Auto-generated method stub
		int[]	caps  = { 4, 1, 4, 1, 2, 1, 2, 1 };
		int[][]	waits = null;

		while ((waits = parseWaits()) != null) {
			int[]	tmp = null;
			int[]	min = { Integer.MAX_VALUE, Integer.MAX_VALUE };
			int		pos = 0;

			for (int i = 0; i < 8; i++) {
				tmp = new int[3];

				for (int j = 0; j < 8; j++) {
					tmp[2]  = (waits[(i + j) % 8][1] - caps[j] >= 0) ? waits[(i + j) % 8][1] - caps[j] : 0;
					tmp[0] += tmp[2];
					tmp[1] *= 10;
					tmp[1] += caps[(8 - i + j) % 8];
				}

				if (min[0] > tmp[0] || (min[0] == tmp[0] && min[1] > tmp[1])) {
					min[0] = tmp[0];
					min[1] = tmp[1];
					pos    = 8 - i;
				}
			}

			
			System.out.printf("%d %d %d %d %d %d %d %d\n",
					caps[(pos + 0) % 8],
					caps[(pos + 1) % 8],
					caps[(pos + 2) % 8],
					caps[(pos + 3) % 8],
					caps[(pos + 4) % 8],
					caps[(pos + 5) % 8],
					caps[(pos + 6) % 8],
					caps[(pos + 7) % 8]);
		}
	}

	private static  int[][] parseWaits() {
		int[][]		waits = null;
		String[]	split = null;
		String		strIn = null;
 
		if ((strIn = parseStdin()) != null) {
			split = strIn.split(" ");
			waits = new int[8][2];
			for (int n = 0; n < split.length; n++) {
				waits[n][0] = n;
				waits[n][1] = Integer.parseInt(split[n]);
			}
		}
		 
		return waits;
	}
 
	private static String parseStdin() {
		String	strNum = null;
 
		try {
			String line = br.readLine();
			if (line != null) {
				if (!line.isEmpty()) {
					strNum = line;
				}
			}
		}
		catch (IOException e) {}
 
		return strNum;
	}
}

Measured memory_bytes: 20412
# include <cmath>
# include <iostream>
# include <queue>
# include <set>
# include <stack>
# include <string>
# include <vector>


using namespace std;


int n;


bool vector_equal(vector<int> &a, vector<int> &b) {
    for (int i=0; i<n; i++) {
        if (a[i] != b[i]) return false;
    }
    return true;
}


int main() {
    cin >> n;

    vector<int> p(n), q(n);
    for (int i=0; i<n; i++) cin >> p[i];
    for (int i=0; i<n; i++) cin >> q[i];

    vector<int> r(n);
    for (int i=0; i<n; i++) r[i] = i+1;

    int np, nq;
    int i = 0;
    do {
        i++;
        if (vector_equal(p, r)) np = i;
        if (vector_equal(q, r)) nq = i;

    } while (next_permutation(r.begin(), r.end()));

    cout << abs(np - nq) << endl;

    return 0;
}



Measured memory_bytes: 888
class Coord
  attr_accessor :x, :y
  def initialize(x, y)
    @x = x
    @y = y
  end
  def north 
    Coord.new(x-1, y)
  end
  def south
    Coord.new(x+1, y)
  end
  def east
    Coord.new(x, y+1)
  end
  def west
    Coord.new(x, y-1)
  end
end

def fetch_next(s, dist, cur_xy, dir)
  nx = nil

  case dir
  when 'n'
    nx = cur_xy.north
    return nil if nx.x < 0
  when 's'
    nx = cur_xy.south
    return nil if nx.x >= s.size
  when 'e'
    nx = cur_xy.east
    return nil if nx.y >= s[0].size
  when 'w'
    nx = cur_xy.west
    return nil if nx.y < 0
  end
  s[nx.x][nx.y] == '.' && dist[nx.x][nx.y] == -1 ? nx : nil
end
    
    

h, w = gets.split("\s").map(&:to_i)
s = []

h.times do |i|
  s[i] = gets.strip
end

dist_max = -1

h.times do |i|
  w.times do |j|
    dist = Array.new(h).map { Array.new(w, -1) }
    cur = Coord.new(i, j)
    dist[cur.x][cur.y] = 0
    places_togo = []
    next if s[cur.x][cur.y] != '.'
    
    loop do  
      ['n', 's', 'e', 'w'].each do |dir|
        next unless nx = fetch_next(s, dist, cur, dir)
        
        places_togo.unshift(nx)
        dist[nx.x][nx.y] = dist[cur.x][cur.y] + 1
      end
      break if places_togo.empty?
    
      cur = places_togo.pop
    end

    d = dist.map { |n| n.max }.max
    dist_max = d if d > dist_max
  end
end

p dist_max
  

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

#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;

  
int main(){
  int n;
  string s, t;
  cin >> n >> s >> t;
  string ans(2*n,'\0');
  
  rep(i, n){
    ans.at(2*i) = s.at(i);
    ans.at(2*i+1) = t.at(i);
  }
  
  cout << ans << endl;
}





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

using namespace std;

int a[105];

int main() {
    int n;
    scanf("%d", &n);

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

    int res = 0;

    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            for (int k = j + 1; k < n; k++) {
                if (a[i] == a[j]) continue;
                if (a[i] == a[k]) continue;
                if (a[j] == a[k]) continue;

                int sum = a[i] + a[j] + a[k];
                int mx = max({a[i], a[j], a[k]});
                if (mx < sum - mx) res++;
            }
        }
    }

    printf("%d\n", res);
}


Measured memory_bytes: 3824
#include<bits/stdc++.h>
#define r_0 return 0
#define pb push_back
#define ll long long
#define ld long double
#define pp pop_back
#define ha v.begin(), v.end()
#define fr first
#define se second
#define Time ios_base::sync_with_stdio(0);
using namespace std;
 const int N = 1e6 + 7;
ll n , x, cnt ,pr =1, b,i,c,ans, d, mn ,y,mx,m,l, zm, sum,z;
string s,s1,s2,s3,ss, s4, s5;
set<int>st;
map<ll,ll>mp,mpp,mppp;
bool tr = 0, t = 0;

ll used[1000001];
deque<int>v,v1,v2;
queue<int>q;
vector<pair<int,int>>vp;



int main()
{
        Time
        ///freopen( "input.txt", "r", stdin );`
        ///freopen( "output.txt", "w", stdout );



        int a[3];
        for ( int i = 0; i < 3; i ++ )
                cin >> a[i];
        cout << a[2] << " " << a[0] << " " << a[1];
}



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

int main()
{
  int64_t N;
  cin >> N;
  vector<int64_t> A(N);
  queue<int64_t> X;
  for (int i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }
  int64_t x1 = 0;
  for (int i = 0; i < N; i++)
  {
    x1 += (i % 2 == 0) ? A.at(i) : -1 * A.at(i);
  }
  X.push(x1);
  int64_t last_x = x1;
  for (int i = 0; i < N - 1; i++)
  {
    int64_t x = 2 * A.at(i) - last_x;
    X.push(x);
    last_x = x;
  }
  while (!X.empty())
  {
    cout << X.front();
    X.pop();
    if (X.empty())
      cout << endl;
    else
      cout << ' ';
  }
}


Measured memory_bytes: 2944
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n, b, f, r, v;
    int[][][] a;
    int i, j, k;

    n = sc.nextInt();
    a = new int[4][3][10];

    for(i = 0;i < n;i++){
      b = sc.nextInt();
      f = sc.nextInt();
      r = sc.nextInt();
      v = sc.nextInt();
      a[b - 1][f - 1][r - 1] += v;
    }

    for(i = 0;i < 4;i++){
      for(j = 0;j < 3;j++){
        for(k = 0;k < 10;k++){
          System.out.print(" " + a[i][j][k]);
        }
        System.out.println();
      }
      if(i == 3)break;
      System.out.println("####################");
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 21068
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
constexpr double pi=3.14159265358979;
 
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;
}
using namespace std;

void solve(){
  ll n;
  cin>>n;
  int ans=100;
  for(ll i=1;i*i<=n;++i){
    if(n%i==0){
      string s=to_string(i);
      string t=to_string(n/i);
      int cmp=max(s.size(),t.size());
      ans=min(ans,cmp);
    }
  }
  cout<<ans<<"\n";
  return;
}
 
signed main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
  cout<<fixed<<setprecision(20);
	solve();
	return 0;
}

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

const int maxn = 1010;

int n, a[maxn][maxn], p[maxn], t[maxn], ans, v[maxn];
queue<int> q, nq;

int main() {
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j < n; ++j)
			cin >> a[i][j];
		q.push(i);
		v[i] = 1;
	}
	for (ans = -1; !q.empty(); ans++) {
		nq = q;
		while (!q.empty()) {
			int i = q.front(); q.pop();
			t[i] = a[i][++p[i]];
			v[i] = 0;
		}
		while (!nq.empty()) {
			int i = nq.front(); nq.pop();
//			printf("%d ", i);
			if (!v[i] && t[t[i]] == i) {
				q.push(i);
				q.push(t[i]);
				v[i] = v[t[i]] = 1;
//				printf("(%d, %d) ", i, t[i]);
			}
		}
//		putchar('\n');
	}
	for (int i = 1; i <= n; ++i)
		if (p[i] != n)
			ans = -1;
	printf("%d\n", ans);
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int a,b,x;
  cin >> a>>b>>x;
  if(a<=x && a+b >= x) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 3600