akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <bitset>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <string>
#include <algorithm>
#include <cmath>
#include <limits>

using namespace std;
using ll=long long;
using vint=vector<int>;
using pint=pair<int,int>;

const double EPS = 1e-9;
const int inf = numeric_limits<int>::max();

#define rep(i,n) for(int i=0;i<int(n);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define SHOW(a) cout << #a << " = " << a << endl
#define ARR(a,i,n) for(int i=0;i<int(n);++i) cout << #a << "[" << i << "]" << " = " << a[i] << endl

void solve(){
	string a, b, c;
	cin >> a >> b >> c;
	cout << a[0] << b[1] << c[2] << endl;
}

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

Measured memory_bytes: 256
#import <Foundation/Foundation.h>
@interface NSMutableDictionary (Extension)
-(void)incrementIntegerValueForKey:(id)key; // key に対応する NSInteger の値を1増加させる。key がない場合は新規設置して 1 を設定する。
@end
@implementation NSMutableDictionary (Extension)
-(void)incrementIntegerValueForKey:(id)key
{
    id value = [self objectForKey: key];
    if (value) {
        [self setObject: @([value integerValue] + 1) forKey: key];
    } else {
        [self setObject: @1 forKey: key];
    }
}
@end
typedef long long INT;
int main(){
    @autoreleasepool {
        int N;
        scanf("%d", &N);
        INT x[50] = {0};
        INT y[50] = {0};
        for(int i=0;i<N;i++){
            scanf("%lld %lld",x+i,y+i);
        }
        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++) {
                if (i==j) continue;
                INT X = x[j] - x[i];
                INT Y = y[j] - y[i];
                NSString *key = [NSString stringWithFormat:@"%lld %lld",X,Y];
                [dic incrementIntegerValueForKey:key];
            }
        }
        NSInteger max = -NSIntegerMax;
        for (id key in [dic keyEnumerator]) {
            max = MAX(max, [[dic valueForKey: key] integerValue]);
        }
        printf("%ld", (N==1) ? 1 : N-max);
    }
}


Measured memory_bytes: 8356
#include <bits/stdc++.h>
#include <string>
#include <vector>
/* 変数i を n回繰り返すマクロ */
#define rep(i,n) for (int i = 0;i < (n);i++)
typedef long long int ll;
using namespace std;
using Graph = vector<vector<int>>;
/* map_for : mapでfor文を回す */
/* gcd_lcm : 最大公倍数 & 最小公約数 */
int main()
{
    cout << fixed << setprecision(10);//小数点以下10桁出力
    ll n,k;
    cin >> n >> k;
    ll am;

    am = n % k;
    ll ab = abs(am - k);
    if(ab > am){
        cout << am << endl;
    }else{
        cout << ab << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)

bool isok(int a, int b, int c, int d){
  bool ok = (a == 0 && b == 2 && d == 1) || (a == 0 && c == 2 && d == 1) || (b == 0 && c == 2 && d == 1) || (b == 0 && c == 1 && d == 2) ||
          (b == 2 && c == 0 && d == 1);
  ok = !ok;
  return ok;
}

const ll MOD = 1e9 + 7;

int main() {

  int N;
  cin >> N;

  //vector<vector<vector<vector<ll>>>> dp(N + 1, vector<ll>(4, vector<ll>(4, vector<ll>(4, 0))));
  ll dp[110][4][4][4] = {0LL};

  REP(i, N)REP(a, 4)REP(b, 4)REP(c, 4)REP(d, 4){
    if (i < 2) continue;
    if (i == 2) {
      if (!((a == 0 && b == 2 && c == 1) || (a == 0 && b == 1 && c == 2) || (a == 2 && b == 0 && c == 1))) dp[i][a][b][c] = 1;
    }
    else if (isok(a, b, c, d)) dp[i][b][c][d] = (dp[i - 1][a][b][c] + dp[i][b][c][d]) % MOD;
  }

  ll ans = 0;

  REP(a, 4)REP(b, 4)REP(c, 4) ans = (ans + dp[N - 1][a][b][c]) % MOD;

  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 256
import java.io.*;

public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		 BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		 Integer case_num = 1;
		 while(true){
			 String input = in.readLine();
			 if(input.equals("0")){
				 break;
			 }
			 System.out.println("Case " + case_num + ": " + input);
			 case_num += 1;
		 }
	}

}

Measured memory_bytes: 27884
#include <iostream>
using namespace std ;
int main(){
       string a ;
       string t ;
       cin >> a >> t ;
       int r=0;
       int m=a.size();
       int m1=t.size();
       for (int i=0, j=0; j <m1,i<m; j++,i++){
        if (a[i]!=t[j])
            r++;
       }
       cout << r;

    }











Measured memory_bytes: 3872
#include <iostream>

using namespace std;

int main(){
  int N, M;
  cin >> N >> M;
  long long int a[M];
  long long int dp[N+1];
  long long int mod = 1000000007;
  for(int i=0; i<M; i++) cin >> a[i];
  int j=0;
  dp[0] = 1;
  if(a[0] == 1){
    dp[1] = 0;
    j++;
  }
  else dp[1] = 1;
  for(int i=2; i<N+1; i++){
    if(i == a[j]){
      dp[i] = 0;
      j++;
    }
    else dp[i] = (dp[i-1]+dp[i-2])%mod;
  }
  cout << dp[N] << endl;
  return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<math.h>

int main(void)
{
  //nとdを入力
  int n,d;
  scanf("%d%d",&n,&d);

  //n個の座標をforで入力
  int i,j,k;
  int x[n][d];
  for(i=0;i<n;i++)
    for(k=0;k<d;k++)
      scanf("%d",&x[i][k]);

  //計算開始
  float dist;
  int cnt=0;
  //i,jを決める
  for(i=0;i<n;i++)
    for(j=i+1;j<n;j++){

      //点iと点jの距離を求める
      dist = 0;
      for(k=0;k<d;k++)
        dist += pow((x[i][k]-x[j][k]),2);
      dist = sqrt(dist);
      
      //ceil(切り上げ関数)とfloor(切り捨て関数)を使ってdistが整数か判定
      //distが整数ならcntを1増やす
      if(ceil(dist)==floor(dist))
        cnt++;
    }

  //cntを出力して終了
  printf("%d\n",cnt);
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
int main() {
	int a, b;
	std::cin>>a>>b;
	int count = 1;
	if (b == 1)
		count = 0;
	int a_count = a;
	for (int i = 0; ; i++) {
		if (a_count >= b)
			break;
		else {
			count++;
			a_count += (a - 1);
		}
	}
	std::cout<<count<<std::endl;
}

Measured memory_bytes: 256
#include<unordered_map>
#include<utility>
template<typename T>
class UnionFind {
 public:
  void unite(const T& a, const T& b) {
    auto x = find(a), y = find(b);
    if(rank_[x] < rank_[y]) std::swap(x, y);
    parent_[y] = x;
    if(rank_[x] == rank_[y]) rank_[x] += 1;
  }
  T find(const T& x) {
    if(!parent_.count(x)) {
      rank_[x] = 1;
      return parent_[x] = x;
    }
    return (parent_[x] == x) ? x : (parent_[x] = find(parent_[x]));
  }
 private:
  std::unordered_map<T, T> parent_;
  std::unordered_map<T, int> rank_;
};

#include<bits/stdc++.h>
using namespace std;

struct Point {int id, x, y;};
struct Edge {int u, v; double w;};

bool cw(auto a, auto b, auto c) {
  auto x1 = b.x - a.x, y1 = b.y - a.y;
  auto x2 = c.x - a.x, y2 = c.y - a.y;
  return x1 * y2 - y1 * x2 < 0;
}

vector<Edge> convex_hull(auto P) {
  sort(begin(P), end(P), [](auto lhs, auto rhs) {
    if(lhs.x != rhs.x) return lhs.x < rhs.x;
    if(lhs.y != rhs.y) return lhs.y < rhs.y;
    return lhs.id < rhs.id;
  });
  P.insert(end(P), rbegin(P) + 1, rend(P));
  vector<Point> ch;
  for(auto p: P) {
    while(ch.size() >= 2 && cw(ch[ch.size() - 2], ch.back(), p)) ch.pop_back();
    ch.emplace_back(p);
  }
  vector<Edge> res;
  for(auto i = 1; i < ch.size(); ++i) {
    Edge e;
    e.u = ch[i - 1].id;
    e.v = ch[i].id;
    e.w = hypot(ch[i - 1].x - ch[i].x, ch[i - 1].y - ch[i].y);
    res.emplace_back(e);
  }
  return res;
}

double Kruskal(auto P, auto E) {
  double res = 0;
  UnionFind<int> uf;
  for(auto i: convex_hull(P)) {
    uf.unite(i.u, i.v);
    res += i.w;
  }
  sort(begin(E), end(E), [](auto lhs, auto rhs) {
    if(lhs.w != rhs.w) return lhs.w < rhs.w;
    if(lhs.u != rhs.u) return lhs.u < rhs.u;
    return lhs.v < rhs.v;
  });
  for(auto e: E) {
    if(uf.find(e.u) == uf.find(e.v)) continue;
    uf.unite(e.u, e.v);
    res += e.w;
  }
  return res;
}

int main() {
  int V, R;
  cin >> V >> R;

  vector<Point> P(V);
  for(auto i = 0; i < V; ++i) {
    P[i].id = i;
    cin >> P[i].x >> P[i].y;
  }

  vector<Edge> E(R);
  for(auto& i: E) {
    cin >> i.u >> i.v;
    --i.u;
    --i.v;
    i.w = hypot(P[i.u].x - P[i.v].x, P[i.u].y - P[i.v].y);
  }

  cout << setprecision(6) << fixed << Kruskal(P, E) << endl;
}

Measured memory_bytes: 3368
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<int, int>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

#include <iomanip>
#include <cmath>
const double pi = acos(-1);

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int r;
    cin, r;
    cout << fixed << setprecision(15) << 2 * r * pi << endl;
    return 0;
}


Measured memory_bytes: 3800
#定義
costA = []
costB = []

# ロジック
A,B,M = map(int,input().split()) # A(冷蔵庫)の種類、B(電子レンジ)の種類、M(割引券)の数
x = [[] for i in range(M)]
y = [[] for i in range(M)]
c = [[] for i in range(M)]
costA = input().split()
costB = input().split()
for i in range(M):
  x[i],y[i],c[i] = map(int,input().split()) # x[i]=割引できるA(冷蔵庫)の種類、
                                            # y[i]=割引できるB(電子レンジ)の種類、
                                            # c[i]=割引額
mincostA = int(costA[0])
for j in range(A):
  if int(costA[j]) < mincostA:
    mincostA = int(costA[j])

mincostB = int(costB[0])
for k in range(B):
  if int(costB[k]) < mincostB:
    mincostB = int(costB[k])

teika = mincostA + mincostB

for l in range(M):
  ind1 = x[l] - 1
  out1 = int(costA[ind1]) 
  ind2 = y[l] - 1
  out2 = int(costB[ind2])
  if (out1 + out2 - int(c[l])) < teika:
    teika = (out1 + out2 - int(c[l]))

print(teika)


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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
 
#define ll long long
ll mod = 1000000000+7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);  
    cout.tie(NULL);
    ll T;
    T=1;
    //cin>>T;
    start:
    while(T--)
    {
       string a,b;
       cin>>a>>b;
       ll ans = 0;
       for(int i=0;i<a.size();i++)
       {
           if(a[i]!=b[i]){ans++;}
       }
       cout<<ans<<endl;
        
    }
    return 0;
}



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

typedef long long ll;

ll INF = 100000000000000;

int main() {
    int N, M, X;
    ll ans = INF;
    cin >> N >> M >> X;
    vector<ll>c(N);
    ll A[N][M];
    for (int i = 0; i < N; i++) {
        cin >> c[i];
        for (int j = 0; j < M; j++) {
            cin >> A[i][j];
        }
    }

    for (ll bits = 0; bits < (1 << N); bits++) {
        ll cost = 0;
        vector<ll>total(M);
        for (int i = 0; i < N; i++) {
            if (bits & (1 << i)) {
                cost += c[i];
                for (int j = 0; j < M; j++) {
                    total[j] += A[i][j];
                }
            }
        }
        bool check = true;
        for (int i = 0; i < M; i++) {
            if (total[i] >= X) {
                continue;
            } else {
                check = false;
                break;
            }
        }
        if (check) {
            ans = min(ans, cost);
        }
    }
    if (ans == INF) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
}


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

int main(){
  string s;
  cin>>s;
  int a=0,z=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='A'){
      a=i;
      break;
    }
  }
  for(int i=0;i<s.size();i++){
    if(s[i]=='Z') z=i;
  }
  cout<<z-a+1<<endl;
}


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

bool x(int k, int &n,vector<int> &a,vector<int> &b){
    for(int j=0; j<n; j++){
      if(a[k]==b[j])return true;
    }
  return false;
}
int main() {
  vector<int> a(9);
  for(int i=0; i<9; i++)cin >>a[i];
  int n;
  cin>>n;
  vector<int> b(n);
  for(int i=0; i<n; i++)cin>>b[i];
  
  if((x(0,n,a,b)&&x(1,n,a,b)&&x(2,n,a,b))||
     (x(0,n,a,b)&&x(3,n,a,b)&&x(6,n,a,b))||
     (x(0,n,a,b)&&x(4,n,a,b)&&x(8,n,a,b))||
     (x(2,n,a,b)&&x(5,n,a,b)&&x(8,n,a,b))||
     (x(6,n,a,b)&&x(7,n,a,b)&&x(8,n,a,b))||
     (x(2,n,a,b)&&x(4,n,a,b)&&x(6,n,a,b))||
     (x(3,n,a,b)&&x(4,n,a,b)&&x(5,n,a,b))||
     (x(1,n,a,b)&&x(4,n,a,b)&&x(5,n,a,b))
    )cout<<"Yes";
  else{cout<<"No";}
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAX_N 15
#define MAX_M 100005

int n,d,x;
int p[MAX_N][MAX_N];
int dp[MAX_N];
int DP[MAX_N][MAX_M];
int t[MAX_N],u[MAX_N];

void solve(int v,int x){
  for(int i=0;i<n;i++){
    t[i]=p[v][i]-p[v-1][i];
    u[i]=p[v-1][i];
  }
  
  for(int i=0;i<n;i++){
    for(int j=0;j<=x;j++){
      if(i)DP[i][j]=DP[i-1][j];
      else DP[i][j]=0;
      if(j-u[i]>=0)
	DP[i][j]=max(DP[i][j],DP[i][j-u[i]]+t[i]);
    }
  }
}

int main(){
  cin>>n>>d>>x;
  dp[0]=x;
  for(int i=0;i<d;i++){
    for(int j=0;j<n;j++)cin>>p[i][j];
    if(i==0)continue;
    solve(i,dp[i-1]);
    dp[i]=dp[i-1]+DP[n-1][dp[i-1]];
  }
  cout<<dp[d-1]<<endl;
  return 0;
}

Measured memory_bytes: 3872
S_cards=[]
H_cards=[]
C_cards=[]
D_cards=[]

for i in range(1,14):
    S_cards.append(i)
    H_cards.append(i)
    C_cards.append(i)
    D_cards.append(i)

now_cards=int(input())
for i in range(0,now_cards):
    kind_num=[]
    kind_num=input().split()
    if kind_num[0]=='S':
        S_cards.remove(int(kind_num[1]))
    elif kind_num[0]=='H':
        H_cards.remove(int(kind_num[1]))
    elif kind_num[0]=='C':
        C_cards.remove(int(kind_num[1]))
    elif kind_num[0]=='D':
        D_cards.remove(int(kind_num[1]))
for i in range(0,len(S_cards)):
    print('S',S_cards[i])
for i in range(0,len(H_cards)):
    print('H',H_cards[i])
for i in range(0,len(C_cards)):
    print('C',C_cards[i])
for i in range(0,len(D_cards)):
    print('D',D_cards[i])

Measured memory_bytes: 7748
#include<iostream>
#include<cstring>
using namespace std;
char s1[1001],s2[1001];
int main()
{
	cin>>s1>>s2;
	int len1=strlen(s1),len2=strlen(s2);
	int i=0;
	while(i<len2)
	{
		cout<<s1[i]<<s2[i];
		i++;
	}
	if(len1>len2)
		cout<<s1[len1-1]<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;++i)
#define fod(i,a,b) for(int i=a;i>=b;--i)
const int N=2115;
const int INF=1e7;
typedef long long LL;
using namespace std;
vector <int> ap[N];
int n,n1,st,ed,f[N][N];
LL ans,pr[N][N];
void link(int x,int y,int w,LL c)
{
	ap[x].push_back(y);
	f[x][y]=w,pr[x][y]=c;
	ap[y].push_back(x);
	f[y][x]=0,pr[y][x]=-c;
}
typedef vector<int>::iterator IT;
namespace Flow
{
	LL dis[N];
	bool bz[N];
	IT cur[N];
	queue<int> d;
	bool spfa()
	{
		while(!d.empty()) d.pop();
		memset(dis,107,sizeof(dis));
		memset(bz,0,sizeof(bz));
		dis[st]=0,bz[st]=1,d.push(st);
		fo(i,1,n1) cur[i]=ap[i].begin();
		while(!d.empty())
		{
			int k=d.front();d.pop();
			for(IT i=ap[k].begin();i!=ap[k].end();i++)	
			{
				int p=*i;
				if(f[k][p]&&dis[k]+pr[k][p]<dis[p]) 
				{
					dis[p]=dis[k]+pr[k][p];
					if(!bz[p]) bz[p]=1,d.push(p);
				}
			}
			bz[k]=0;
		}
		return (dis[ed]<=1e17);
	}
	int flow(int k,int s)
	{
		if(k==ed) return s;
		int sl=0,v;
		bz[k]=1;
		for(;cur[k]!=ap[k].end();cur[k]++)
		{
			int p=*cur[k];
			if(!bz[p]&&f[k][p]&&dis[p]==dis[k]+pr[k][p]) 
			{
				if(v=flow(p,min(s,f[k][p]))) 
				{
					sl+=v,s-=v;
					f[k][p]-=v,f[p][k]+=v;
					ans+=(LL)v*pr[k][p];
					if(!s) break;
				}
			}
		}
		bz[k]=0;
		return sl;
	}
}
using Flow::flow;
using Flow::spfa;
int main()
{	
	cin>>n;
	n1=2*n+6,st=2*n+5,ed=n1;
	fo(i,1,n) 
	{
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		link(st,i,z,0);
		link(i,2*n+1,z,x+y);
		link(i,2*n+2,z,x-y);
		link(i,2*n+3,z,-x+y);
		link(i,2*n+4,z,-x-y);
	}  
	fo(i,1,n) 
	{
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		link(i+n,ed,z,0);
		link(2*n+1,i+n,z,-x-y);
		link(2*n+2,i+n,z,-x+y);
		link(2*n+3,i+n,z,x-y);
		link(2*n+4,i+n,z,x+y);
	}
	ans=0;
	while(spfa()) 
		flow(st,INF);
	printf("%lld\n",-ans);
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

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

struct edge {
	int to, cost;
	edge(int t,int c):to(t),cost(c) {}
};


//-----------------------------------------------------------------------------

string s;
int cnt;

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

	cin>>s;
	REP(i,6) if(s[i]=='1') cnt++;
	cout<<cnt<<endl;

	return 0;
}


Measured memory_bytes: 256
//#include "stdafx.h"
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <unordered_map>
#include <cstdint>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long long int	QWORD;
typedef unsigned long long		SQWORD;

/*-----------------------------------------------------------------------------
　メイン
 -------------------------------------------------------------------------------*/
int main()
{
	int N, x;
	cin >> N >> x;
	vector<ll> a(N);
	REP(i, N) cin >> a[i];

	ll ans = 0;
	for (int i = 0; i < N - 1; i++) {
		ll sum = a[i] + a[i + 1];
		ll subTotal = max((ll)0, sum - x);
		ll subOne = min(subTotal, a[i + 1]);
		a[i + 1] -= subOne;
		a[i] -= (subTotal - subOne);
		ans += subTotal;
	}
	cout << ans << endl;
	return 0;
}



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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

ll N;
vector<ll> A, B;

enum Player { Alice = 0, Bob = 1 };

signed main()
{
    cin >> N;
    A.resize(N);
    B.resize(N);
    REP(i, N) { cin >> A[i] >> B[i]; }

    vector< tuple<ll, ll, ll> > AB; // max, A, B
    REP(i, N) {
        AB.push_back(make_tuple(A[i] + B[i], A[i], B[i]));
    }
    sort(AB.begin(), AB.end(), greater< tuple<ll, ll, ll> >() );

    ll alice = 0;   // takahashi
    ll bob = 0;
    ll player = Alice;
    REP(i, N) {
        if(player == Alice) {
            alice += get<1>(AB[i]);
            player = Bob;
        }
        else {
            bob += get<2>(AB[i]);
            player = Alice;
        }
    }
    printf("%lld\n", alice - bob);

    return 0;
}


Measured memory_bytes: 5876
h,w=map(int,input().split())
l=[]
for i in range(h):
    l.append(list(map(int,input().split())))
#print(*l)
ans=[]
for i in range(h):
    for j in range(w):
        i2,j2=i,j
        if i2%2: j2=w-(j+1)
#        print(l[i2][j2],i+1,j2+1)
        o,p=i2,j2
        if l[i2][j2]%2:
            if i2%2==0 and j2<w-1: p+=1
            elif i2%2==0 and i2<h-1: o+=1
            elif i2%2 and j2>0: p-=1
            elif i2%2 and i2<h-1: o+=1
            if i2!=o or j2!=p:
                l[i2][j2]-=1
                l[o][p]+=1
                ans.append((i2+1,j2+1,o+1,p+1))

print(len(ans))
for i in range(len(ans)):
    print(*ans[i])


Measured memory_bytes: 26744
#include <iostream>
#include <vector>
using namespace std;
int main(void)
{
	vector<long> v;
	long a, b;
	char op;
	while (1)
	{
		cin >> a >>op>> b;
		if (op == '?')break;
		else if (op == '+')v.push_back(a + b);
		else if(op=='-')v.push_back(a - b);
		else if (op == '*')v.push_back(a * b);
		else if (op == '/')v.push_back(a / b);
	}
	for (long l : v)
	{
		cout << l << endl;
	}
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;



int main(){
  string s;
  cin >> s;
  bool ok = false;
  REP(i,s.size()){
    if(s[i] == '9') ok = true;
  }

  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
/*
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<numeric>
#include<iomanip>
#include<utility>
#include<cstdlib>
#include<typeinfo>
#include<stack>
#include<cassert>
#include<functional>
*/
#define int long long int
#define double long double
using namespace std;
#define INT_DMAX 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define rep(i,n) for(int (i)=0, i##_len = (n);(i)<i##_len;(i)++)
#define reps(i,x) for(int (i)=1;(i)<=(int)(x);(i)++)
#define rrep(i,x) for(int (i)=((int)(x)-1);(i)>=0;(i)--)
#define rreps(i,x) for(int (i)=((int)(x));(i)>0;(i)--)
#define FOR(i,a,b) for (int (i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define bit(n) ((int)(1)<<(n))
#define all(x) (x).begin(),(x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl 
#define nint int
using namespace std;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
typedef pair<int,int> p;
typedef pair<double,double> dop;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;


signed main()
{
int h,w;
std::cin >> h >> w;
int mins = INF;

if(mins > w){
    mins = w;
}
if(mins > h){
    mins = h;
}
if(w % 3 == 0 || h % 3 == 0){
    mins = 0;
}

for(int i = 0; i <= h; i++){
    int f = i * w;
    int s = (h - i) * (w/2);
    int t = (h - i) * (w / 2 + w % 2);
    int ff = abs(f - s);
    int ss = abs(s - t);
    int tt = abs(t - f);
    if(mins > max(ff,max(ss,tt))){
        mins = max(ff,max(ss,tt));
    }
}
for(int i = 0; i <= w; i++){
    int f = i * h;
    int s = (w - i) * (h/2);
    int t = (w - i) * (h / 2 + h % 2);
    int ff = abs(f - s);
    int ss = abs(s - t);
    int tt = abs(t - f);
    if(mins > max(ff,max(ss,tt))){
        mins = max(ff,max(ss,tt));
    }
}
std::cout << mins << std::endl;
return 0;
}

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


const int INF = 1001001001;
int c[10][1005];


int main() {
  int H, W, K;
  cin >> H >> W >> K;
  vector<string> S(H);
  rep(i, H) cin >> S[i];
  
  int ans = INF;
  // 横に切る箇所を全探索
  rep(div, 1<<(H - 1)){
    // 分割した後に各行が上から何番目のグループかを保持する変数
    int g = 0;
    vector<int> id(H);
    rep(i, H) {
      id[i] = g;
      // i桁目が1か確認
      if (div>>i&1) g++;
    }
    g++;

    rep(i ,g) rep(j, W) c[i][j] = 0;
    rep(i, H) rep(j, W) c[id[i]][j] += (S[i][j]-'0');

    int num = g - 1;
    vector<int> now(g);
    auto add = [&](int j) {
      rep(i,g) now[i] += c[i][j];
      rep(i,g) if (now[i] > K) return false;
      return true;
    };
    rep(j, W) {
      if (!add(j)) {
        num++;
        now = vector<int>(g);
        if (!add(j)) {
          num = INF;
          break;
        }
      }
    }
    ans = min(ans, num);
  }

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


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

int main(){
  int A=0,B=0,C=0,D=0,E=0,F=0,G=0,H=0,I=0,J=0,K=0,L=0,M=0,N=0,O=0,P=0,Q=0,R=0;
  string S,T,U;
  cin >> S >> T;
  cin >> A >> B;
  cin >> U;
  if(U==S){
    A--;
  }
  else{
    B--;
  }
  cout << A << " " << B <<endl;
  
  return 0;
}


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

#define pb(a) push_back(a)

typedef long long ll;
const ll inf = 1e9+7;
const int MAX_N = 1e5+5;
int dx[] = {-1,0,1,0},dy[] = {0,1,0,-1};
vector<ll> prime;

ll inv[MAX_N],fac[MAX_N];

template <class T = ll> T in(){T x;cin >> x;return x;}

inline ll GCD(ll a,ll b){ll c;while(b!=0){c=a%b;a=b;b=c;}return a;}
inline ll LCM(ll a,ll b){return a*b/GCD(a,b);}
inline ll POW(ll a,ll b){ll c=1;while(b>0){if(b&1){c=a*c%inf;}a=a*a%inf;b>>=1;}return c;}
inline void _nCr(){fac[0]=1;for(int i=1;i<MAX_N;i++){fac[i]=fac[i-1]*i%inf;}for(int i=0;i<MAX_N;i++){inv[i]=POW(fac[i],inf-2);}}
inline ll nCr(ll n,ll r){return (fac[n]*inv[r]%inf)*inv[n-r]%inf;}
inline void PRI(ll n){bool a[n+1];for(int i=0;i<n+1;i++){a[i]=1;}for(int i=2;i<n+1;i++){if(a[i]){prime.pb(i);ll b=i;while(b<=n){a[b]=0;b+=i;}}}}

class UnionFind {
private:
	int par[MAX_N];
	int rank[MAX_N];
public:
	void init(int n);
	int find(int x);
	void unite(int x,int y);
	bool same(int x,int y);
};

void UnionFind::init(int n) {
	for (int i = 0;i < n;i++) {
		par[i] = i;
		rank[i] = 0;
	}
}

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

void UnionFind::unite(int x,int y) {
	x = find(x);
	y = find(y);
	if (rank[x] < rank[y]) par[x] = y;
	else {
		par[y] = x;
		if (rank[x] == rank[y]) rank[x]++;
	}
}

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

UnionFind uf;

int main() {
	int n = in();ll W = in();
	ll w[n],v[n];
	ll www;
	vector<ll> wwww[4];
	for (int i = 0;i < n;i++) {
		w[i] = in();v[i] = in();
		if (!i) www = w[i];
		wwww[w[i]-www].pb(v[i]);
	}
	for (int i = 0;i < 4;i++) {
		sort(wwww[i].begin(),wwww[i].end(),greater<ll>());
	}
	ll ans = 0;
	ll v0=0,v1=0,v2=0,v3=0;
	for (int i = 0;i <= wwww[0].size();i++) {
		if (i > 0) v0+=wwww[0][i-1];
		for (int j = 0;j <= wwww[1].size();j++) {
			if (j > 0) v1+=wwww[1][j-1];
			for (int k = 0;k <= wwww[2].size();k++) {
				if (k > 0) v2+=wwww[2][k-1];
				for (int l = 0;l <= wwww[3].size();l++) {
					if (l > 0) v3+=wwww[3][l-1];
					if (www*i+(www+1)*j+(www+2)*k+(www+3)*l <= W) {
						ans = max(ans,v0+v1+v2+v3);
					}
				}
				v3=0;
			}
			v2=0;
		}
		v1=0;
	}
	cout << ans << endl;
}

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

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

    vector<int> a(n);
    vector<int> b(n);
    for(int in=0;in<n;in++) {
        cin >> a[in] >> b[in];
    }

    sort(a.begin(), a.end());
    sort(b.begin(), b.end());

    int ans, mid, mid1, mid2;
    if(n%2==1) {
        mid = n / 2;
        ans = b[mid] - a[mid] + 1; 
    }
    else {
        mid2 = n / 2;
        mid1 = mid2 - 1;
        int aa, bb;
        aa = a[mid2]+a[mid1];
        bb = b[mid2]+b[mid1];
        ans = bb - aa + 1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4700
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

const INF: usize = 1 << 60;

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let N: usize = sc.get();
    let mut ans = INF;
    for i in (1..).take_while(|k| k * k <= N) {
        if N % i == 0 {
            ans = min(ans, i - 1 + N/i - 1);
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
H, N = map(int, input().split())

magic = [tuple(map(int, input().split())) for _ in range(N)]

DP = [0] + [10**9]*H

for h in range(H):
  for damage, mp in magic:
    DP[min(h + damage, H)] = min(DP[min(h + damage, H)], DP[h] + mp)
print(DP[H])

Measured memory_bytes: 40944
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
#define ld long double
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a<c && c<b) cout<<"Yes"<<endl;
  else if(b<c && c<a) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

#define fr first
#define sc second
#define mk make_pair

using namespace std;

long long n, ans = 0, k;

int main()
{
    cin >> n >> k;
    if(k == 0)
    {
        cout << n * n;
        return 0;
    }

    for(long long i = k + 1; i <= n; i++)
    {
        ans += (n / i) * (i - k);
        if(n % i >= k)
        {
            ans += ((n % i) - k + 1);
        }
    }

    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "vector"

using namespace std;

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

    int A, B, count, result = 0;

    cin >> A >> B;
    if(B == 1){
        cout << result << "\n";
        return 0;
    }
    for (result = 1; B > (result - 1) * (A - 1) + A; result++);

    cout << result << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;

int main(void) {
    Int m1, d1, m2, d2;
    cin >> m1 >> d1 >> m2 >> d2;
    if (d2 == 1) {
        cout << 1 << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 3628
#include<iostream>
using namespace std;
int main(){
   int H,W,sum=0;
   char a[100][100];
   while(cin>>H>>W){
      for(int i=1;i<=H;i++)
      for(int j=1;j<=W;j++)
      cin>>a[i][j];
      for(int i=1;i<=H;i++)
      for(int j=1;j<=W;j++)
      {
         if(a[i][j]=='#')
         cout<<a[i][j];
         else
         {
            if(a[i-1][j-1]=='#') sum++;
            if(a[i-1][j]=='#')  sum++;
            if(a[i-1][j+1]=='#') sum++;
            if(a[i+1][j]=='#') sum++;
            if(a[i+1][j-1]=='#') sum++;
            if(a[i+1][j+1]=='#') sum++;
            if(a[i][j-1]=='#') sum++;
            if(a[i][j+1]=='#') sum++;
            cout<<sum;
         }
         sum=0;
       if(j==W)
        cout<<endl;
      }
      cout<<endl;
   }

   return 0;
}


Measured memory_bytes: 256
//By Don4ick 
//#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;

#define forn(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define y1 qewr1234

const double PI = acos(-1.0);
const int DIR = 4;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};

const int N = (int)2e5 + 228;
const int LOG = 20;

using namespace std;

int n, x, y, tin[N], tout[N], timer, up[LOG][N], depth[N], ans;
vector < int > g[N], t[N];

void dfs1(int v, int pr)
{
	tin[v] = ++timer;
	for (auto to : t[v])
	{
		if (to == pr)
			continue;
		up[0][to] = v;
		depth[to] = depth[v] + 1;
		dfs1(to, v);	
	}
	tout[v] = timer;
}

bool upper(int v, int u)
{
	return tin[v] <= tin[u] && tout[v] >= tout[u];
}

int lift(int v, int u)
{
	for (int i = LOG - 1; i >= 0; i--)
	{
		if (up[i][v] && !upper(up[i][v], u))
			v = up[i][v];
	}
	return v;
}

int lca(int v, int u)
{
	if (upper(v, u))
		return v;
	if (upper(u, v))
		return u;
	v = lift(v, u);
	return up[0][v];
}

int dist(int v, int u)
{
	int pr = lca(v, u);
	return depth[v] + depth[u] - 2 * depth[pr];
}

void dfs(int v, int pr, int u, int cnt)
{
	ans = max(ans, cnt + 2 * dist(v, u));
	if (u == v)
		return;	
	for (auto to : g[v])
	{
		if (to == pr || to == u)
			continue;	
		int newU = up[0][u];
		if (upper(u, to))
			newU = lift(to, u);
		dfs(to, v, newU, cnt + 2);
		if (dist(v, to) > 2)
		{
			cout << -1 << endl;
			exit(0);
		}
	}
}

int main()
{
	//ios_base::sync_with_stdio(false);
	//cin.tie();
	//cout.tie();		

	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);		

	//~read
	scanf("%d%d%d", &n, &x, &y);
	forn(i, n - 1)
	{
		int v, u;
		scanf("%d%d", &v, &u);
		g[v].pb(u), g[u].pb(v);
	}		
	forn(i, n - 1)
	{
		int v, u;
		scanf("%d%d", &v, &u);
		t[v].pb(u), t[u].pb(v);
	}
	//~dfs1
	dfs1(y, -1);
	for (int i = 1; i < LOG; i++)
	{
		forn(j, n)
		{	
			if (up[i - 1][j])	
				up[i][j] = up[i - 1][up[i - 1][j]];
		}
	}
	//~solve	
	dfs(x, -1, y, 0);
	//~result
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 51968
// Aaradhya Beri
#pragma GCC optimze("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef long double f80;
#define double long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
#define w(x) int x; cin>>x; while(x--)
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
//const int mod=998244353;
const int mod=1000000007;
typedef vector<int> vi;
typedef vector<ll> vl;

int powm(int a, int b) {
    int res=1;
    while(b) {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}
 

signed main() {
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cout<<fixed<<setprecision(8);
    ll n, m;
    cin >> n >> m;
    ll ans = 0;
    if (n >= m / 2)
    {
        ans = m / 2;
    }
    else
    {
        ans = n;
        m -= 2 * n;
        ans += m / 4;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
string s[1005];
int main()
{
	scanf("%d%*d",&n);
	for(int i=0;i<n;i++)
		cin>>s[i];
	sort(s,s+n);
	for(int i=0;i<n;i++)
	{
		cout<<s[i];
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<vector>
#include<map>
#include<algorithm>
#include<set>
#include <cmath>
#include<string.h>
#include <stdio.h>
#include <unordered_map>
#include <queue>
#include<climits>
#include <iomanip>



using namespace std;
#define ll long long
#define clr(x) memset(x, 0, sizeof(x))
#define tcase ll t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define GCJ ll t;cin>>t;for(ll H=1;H<=t;H++){cout<<"CASE #"<<H<<": ";solve();}
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define endl "\n"
//comment out the above line when coding probs which require flushing the output



void solve()
{
    ll n;
    cin>>n;
    ll a[n];
    
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
    }
    
    ll dp[n][n];
    clr(dp);
    
    
    
    ll count = 0, add=0;
    while(count<(n*(n+1))/2)
    {
        for(ll i=0;i+add<n;i++)
        {
            ll j=i+add;
            if(i==j)
            {
                dp[i][j]=a[i];
            }
            else
            {
                dp[i][j]=max(a[i]-dp[i+1][j], a[j]-dp[i][j-1]);
                

            }
            
            
            count++;
        }
        add++;
    }
    
    

    
    cout<<dp[0][n-1]<<endl;
}


int main()
{
    
    
    fast;
    //tcase
    // {
    solve();
    // }
    
}






Measured memory_bytes: 73480
#include <cstdio>
#include <cstring>
using namespace std;

typedef int INT;
const int SIZE = 4194304;
bool HA[SIZE];

inline INT get( char c ) {
    char T[5] = "ACGT";
    for ( INT i = 0; i < 4; ++ i ) {
        if ( c == T[i] ) return i + 1;
    }
    return 0;
}

int main() {
    INT n, sum, t, c;
    while ( scanf("%d", &n) != EOF ) {
        memset( HA, false, sizeof(HA) );
        while ( getchar() != '\n' );
        for ( register INT i = 0; i < n; ++ i ) {
            sum = 0;
            t = 1;
            bool flag = getchar() == 'i';
            while ( getchar() != ' ' );
            while ( ( c = get( getchar() ) ) != 0 ) {
                sum += c * t;
                t *= 4;
            }
            if ( flag ) {
                HA[sum] = true;
            } else {
                puts( HA[sum] ? "yes" : "no" );
            }
        }
    }
    return 0;
}

Measured memory_bytes: 4832
n,m = map(int, input().split())
yen = [list(map(int, input().split())) for _ in range(n)]
yen.sort(key=lambda x:(x[0]))
ans = 0
hon = 0
for i in range(n):
    if hon + yen[i][1] <= m:
        hon += yen[i][1]
        ans += yen[i][0]*yen[i][1]
    else:
        ans += yen[i][0]*(m-hon)
        hon = m
    if hon == m:
        break
print(ans)  


Measured memory_bytes: 29024
from collections import deque
n = int(input())
A = deque(map(str, input().split()))
D = deque()
while A:
  x = A.popleft()
  D.append(x)
  if A:
    y = A.popleft()
    D.appendleft(y)
if n % 2 != 0:
  D.reverse()
print(" ".join(D))

Measured memory_bytes: 30532
#include <stdio.h>

#define DEBT 100000

int main(void)
{
    int n, money = DEBT, i, r;
    
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        money *= 1.05;
        r = money % 1000;
        if (r != 0) {
            money += 1000 - r;
        }
    }
    printf("%d\n", money);
    return 0;
}

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

bool isPrime[10000100];

int main() {

  int n;


  for(int i=1;i <=10000000;i++) isPrime[i] = true;
  isPrime[1] = false;
  
  for(int i=1;i*i<=10000000;i++) {
    
    if(isPrime[i]) {
      for(int j=2;i*j<=10000001;j++) {
	
	isPrime[i*j] = false;
      }
    }
  }
  
  while(1) {
    
    
    cin >> n;
    
    if(n==0) break;
    
    for(int i=n;i>=13;i--) {
      
      if(isPrime[i] && isPrime[i-2] && isPrime[i-6] && isPrime[i-8]){
	cout << i<< endl;
	break;
      }
      
    }

  }
    
    return 0;
  
    
  }
  
  
  

Measured memory_bytes: 10924
// Problem : Count Median
// Contest : Virtual Judge - AtCoder
// URL : https://vjudge.net/problem/AtCoder-abc169_e
// Memory Limit : 1048 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")  // disable
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define lll __int128
#define lp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define vec(v, type, sz) vector<type> v(sz)
#define in(v) \
    for (auto &i : v) cin >> i
#define all(v) v.begin(), v.end()
#define prv(v)                         \
    for (auto i : v) cout << i << " "; \
    cout << "\n"
#define MOD 1000000007
#define INF 1000000000
#define INFL 1000000000000000000ll
#define fast_io                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define vi vector<int>
#define vl vector<ll>
#define vii(v, n, m, val) vector<vector<int>> v(n, vector<int>(m, val))
#define viii(v, i, j, k, val)        \
    vector<vector<vector<int>>> v(i, \
                                  vector<vector<int>>(j, vector<int>(k, val)))
#define pii pair<int, int>
#define pb push_back
#define file_io                       \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define testcases \
    int tcc;      \
    cin >> tcc;   \
    for (int tc = 1; tc <= tcc; tc++)
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while (!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(vector<string> __attribute__((unused)) args,
               __attribute__((unused)) int idx,
               __attribute__((unused)) int LINE_NUM) {
    cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if (idx > 0)
        cerr << ", ";
    else
        cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss;
    ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef DB
#define debug(...) \
    debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

int main() {
    fast_io;
	int n; cin>>n; vi a(n),b(n);
	lp(i,0,n){
		cin>>a[i]>>b[i];
	}
	sort(all(a)); sort(all(b));
	if(n&1){
		int m1=a[n/2],m2=b[n/2];
		cout<<m2-m1+1;
	}else{
		int m1=(a[n/2]+a[n/2-1]),m2=(b[n/2]+b[n/2-1]);
		cout<<m2-m1+1;
		
	}
}

Measured memory_bytes: 4756
#include<bits/stdc++.h>
using namespace std;
int main(){
	int N;
	cin >> N;
	int max = 0;
	for(;;){
		max++;
		if(max * (max + 1) / 2 > N) break;
	}
	int skip = max * (max + 1) / 2 - N;
	for(int i = 1; i <= max; i++){
		if(i == skip) continue;
		cout << i << endl;
	}
	return 0;
}


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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);  
	int n;
	cin >> n;
	if(n % 10 == 0) cout << 10 << endl;
	else {
		int ans = 0;
		while(n > 0) {
			ans += n % 10;
			n /= 10;
		}
		cout << ans << endl;
	}
	return 0;	
}


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

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

int main(void) {
    int N,D;
    cin>>N>>D;

    cout<<(N + (2*D))/(2*D+1)<<endl;

    return 0;
}





Measured memory_bytes: 256
a, b, c, d = gets.strip.split.map(&:to_i)

def count(x, y, d)
  i = (x - 1) / d
  j = y / d
  
  (j - i)
end

ans = (b - a + 1) - count(a, b, c) - count(a, b, d) + count(a, b, c.lcm(d))
puts(ans)

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

int main() {

    int x, y, z; cin >> x >> y >> z;

	int tmp = z;
	int cnt = 0;
	while (true) {
		tmp += y + z;
		if (x < tmp) {
			break;
		}
		cnt++;
	}
	cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn._
object Main extends App {
  val n = readInt
  val s = readLine

  println((1000 to 1999).count { i =>
    i.toString.takeRight(3).foldLeft(0){(z, c) =>
      val i = s.indexOf(c, z)
      if (i == -1) 100000 else i + 1
    } != 100000
  })
}

Measured memory_bytes: 29372
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli > plli;
typedef vector<lli> vlli;
typedef vector<plli > vplli;

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define lcm(a, b) ((a * b) / gcd(a, b))
#define sqr(x) (x)*(x)
#define all(a) a.begin(),a.end()
#define UN(v) sort(all(v)), v.resize(unique(all(v))-v.begin())

#define endl '\n'

const long long INF = 100000000000000000;
const long long MOD = 1000000007;
const long long MAXN = 100005;

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

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

void solve() {
    lli a, b;
    cin >> a >> b;
    if (abs(a + b) % 2 == 1) {
        cout << "IMPOSSIBLE\n";
    } else {
        cout << (a + b) / 2 << "\n";
    }
}

int main()
{
    IOS;
    lli t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256