akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int N, K;
int dp[100005];
vector<int> pillar;
 
int jump(int now, int cost){
    if(dp[now] != -1){
        return cost + dp[now];
    }
    if(pillar.size() == now + 1){
        dp[now] = 0;
    }else if(pillar.size()-1 < now ){
        //dp[now] = abs(pillar[now] - pillar[now + 1]);
        return INT_MAX;
    }else{
        int ans = INT_MAX;
        for (int i = now+1; i <= now+K; ++i)
        {
            ans = min(ans, jump(i, abs(pillar[now] - abs(pillar[i]))));
        }
        dp[now] = ans;
    }
    return cost + dp[now];
}
 
int main(){
    cin >> N >> K;
    for(int i = 0; i < N; i++){
        int input;
        cin >> input;
        pillar.push_back(input);
    }
    memset(dp, -1, sizeof dp);
    cout << jump(0, 0) << endl;
}

Measured memory_bytes: 8952
using System;

namespace ConsoleABC
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();
            string p = s.Substring(0, n / 2);
            p = p + p;
            if (s == p) Console.WriteLine("Yes");
            else Console.WriteLine("No");
         //   Console.ReadLine();
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define N 100100

int n;
int a[N],f[N],g[N];
int f_mx1,f_mx2,f_id,g_mx1,g_mx2,g_id;

int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if (i&1) f[a[i]]++; else g[a[i]]++;
	}
	for (int i=1;i<=100000;i++)
	{
		if (f[i]>f_mx1) {
			f_mx2=f_mx1,f_mx1=f[i];
			f_id=i;
		} else
		if (f[i]>f_mx2) f_mx2=f[i];
		
		if (g[i]>g_mx1) {
			g_mx2=g_mx1,g_mx1=g[i];
			g_id=i;
		} else
		if (g[i]>g_mx2) g_mx2=g[i];		
	}
	if (f_id!=g_id) printf("%d\n",n-f_mx1-g_mx1);
	else printf("%d\n",min(n-f_mx1-g_mx2,n-f_mx2-g_mx1));
	return 0;
}

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

using namespace std;

bool sqrt1(int x) {
    long long int start = 1, end = x, mid;
    while(start <= end) {
        mid = (start + end)/2;
        if (mid*mid <= x) start = mid+1;
        else end = mid-1;
    }
    start--;
    if(start*start == x) return true;
    return false;
}


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s1, s2;
    cin >> s1 >> s2;
    s1 += s2;
    int x = stoi(s1);
    if(sqrt1(x)) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  int M;
  M=max(max(a,b),c);
  if((a+b+c) == 2*M){
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
}

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

int main()
{
    int r, g, b, n;
    cin >> r >> g >> b >> n;
    int ans = 0;
    for(int i = 0; i*r <= n; i++){
        for(int j = 0; i*r + j*g <= n; j++){
            if((n - i*r - j*g)%b == 0) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3584
#include<cstring>
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

string s;

int solve(){
	if(*s.begin() != 'A') return 0;
	int t = 0;
	for(int i = 1; i < s.length(); i++){
		if(islower(s[i])) continue;
		if(s[i] != 'C') return 0;
		if(i == 1 || i == s.length() - 1) return 0;
		t++;
	}
	return t == 1;
}

int main(){
	cin >> s;
	cout << (solve() ? "AC" : "WA") << endl;
	return 0;
}

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

int main() 
{
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    int z = max(a,max(b,c))*pow(2,k);
    cout << a+b+c-max(a,max(b,c))+z;
    return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//typedef vector<vector<ll>> Graph;

const ll mod = 1e9 + 7;
//const ll mod = 998244353;

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define spa << " " <<
#define fi first
#define se second

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 (a>b) { a=b; return 1; } return 0; }

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cerr<<v[i][j];cerr<<endl;}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<endl;};

string num2bit(ll num, ll len){
	string bit = "";
	REP(i, len){
	bit += char('0'+(num>>i & 1));
	}
	reverse(bit.begin(), bit.end());
	return bit;
}

vector<ll> res(1<<17, -1);
ll N;


void dfs(ll X, ll Y, ll mask, ll depth, ll id){

	//dump(num2bit(X, N))
	//dump(num2bit(Y, N))
	//dump(num2bit(mask, N))

	if(depth == N-1){
		res[(id<<1)] = X;
		res[(id<<1)+1] = Y;
		return;
	}

	ll idx = -1;
	REP(i, N){
		bool xi = (X>>i) & 1;
		bool yi = (Y>>i) & 1;
		bool mi = (mask>>i) & 1;
		//dump(xi)
		//dump(yi)
		//dump(mi)
		if(xi != yi and !mi){
			idx = i;
			break;
		} 
	}

	ll nmask = mask^(1ll<<idx);

	ll jdx = -1;
	REP(i, N){
		bool mi = (nmask>>i) & 1;
		if(!mi){
			jdx = i;
			break;
		}
	}

	//dump(idx)
	//dump(jdx)

	ll Z = -1, W = -1;
	Z = X^(1<<jdx);
	W = Z^(1<<idx);

	//dump(num2bit(Z, N))
	//dump(num2bit(W, N))

	dfs(X, Z, nmask, depth+1, (id<<1));
	dfs(W, Y, nmask, depth+1, (id<<1)+1);
	return;
}

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

	ll A, B;
	cin >> N >> A >> B;

	ll X = A^B;

	ll sz = 0;
	REP(i, N) if(X>>i & 1) sz++;

	if(sz%2==0){
		cout << "NO" << endl;
		return 0;
	}
	cout << "YES" << endl;

	dfs(A, B, 0, 0, 0);

	REP(i, 1<<N){
		cout << res[i] << " ";
	}
	cout << endl;

	/*
	REP(i, 1<<N){
		cout << num2bit(res[i], N) << " ";
	}
	cout << endl;
	*/

	return 0;
}

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


struct edge{ int to,cost; };
int N,Q;

vector<edge> G[100005];

int parent[100005];
int depth[100005];
int dist[100005];

int p[30][100005];
void dfs(int pos,int prev,int Depth,int Dist){
  parent[pos]=prev;
  depth[pos]=Depth;
  dist[pos]=Dist;
  for(int i=0;i<(int)G[pos].size();i++){
    edge e=G[pos][i];
    if(e.to==prev)continue;
    dfs(e.to,pos,Depth+1,Dist+e.cost);
  }
}

int lca(int a,int b){
  if(depth[a]>depth[b])swap(a,b);
  
  int s=(depth[b]-depth[a]);
  for(int i=0;i<30;i++)
    if(s>>i&1)
      b=p[i][b];
  
  if(a==b)return a;
  
  for(int i=29;i>=0;i--){
    if( p[i][a] != p[i][b] ){
      a=p[i][a];
      b=p[i][b];
    }
  }
  return parent[a];
}

int calc_dist(int a,int b){
  int c=lca(a,b);
  return dist[a]-dist[c]+dist[b]-dist[c];
}

int check(int p,int a,int b,int c){
  int res=0;
  res=max(res, calc_dist(p,a));
  res=max(res, calc_dist(p,b));
  res=max(res, calc_dist(p,c));
  return res;
}

int solve(int a,int b,int c){
  int x=lca(b,c);
  if( calc_dist(x,b) > calc_dist(x,c) )swap(b,c);
  
  int y=calc_dist(b,c)/2;
  int z=c;
  for(int i=29;i>=0;i--){
    int nz=p[i][z];
    if(nz!=-1 && (dist[c]-dist[nz]) <= y){
      z=nz;
    }
  }
  
  int res=check(z,a,b,c);
  if( parent[z]!=-1 )
    res=min(res,check(parent[z],a,b,c));
  return res;
}

int main(){
  scanf("%d %d",&N,&Q);
  for(int i=0;i<N-1;i++){
    int u,v,w;
    scanf("%d %d %d",&u,&v,&w);
    u--;
    v--;
    G[u].push_back( (edge){v,w} );
    G[v].push_back( (edge){u,w} );
    
  }
  
  dfs(0,-1,0,0);

  for(int i=0;i<N;i++)
    p[0][i]=parent[i];

  for(int i=1;i<30;i++){
    for(int j=0;j<N;j++){
      int x=p[i-1][j];
      if(x!=-1)x=p[i-1][x];
      p[i][j]=x;
    }
  }

  for(int i=0;i<Q;i++){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    a--;
    b--;
    c--;
    int ans=(1<<30);
    ans=min(ans, solve(a,b,c) );
    ans=min(ans, solve(b,a,c) );
    ans=min(ans, solve(c,a,b) );
    printf("%d\n",ans);
  }
  return 0;
}



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

int main()
{

    string s,t;
    cin >> s;
    cin >> t;

    if(t.erase(t.size() -1) == s){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;

}

Measured memory_bytes: 3632
n = int(input())
s = []
for i in range(n):
    s.append(input())

d = {}
for word in s:
    if word not in d.keys():
        d[word] = 1
    else:
        d[word] += 1

max_v = max(d.values())
d = sorted(d.items(), key=lambda x: x[0])

for k, v in d:
    if v == max_v:
        print(k)


Measured memory_bytes: 46348
#include <iostream>

void print(int *sort, int N);
void insert_sort(int *sort, int N);

int main()
{
    int N;
    int *sort;
    
    while(std::cin >> N)
    {
        sort = new int[N];
        
        for(int i = 0; i < N; i++)
        {
            std::cin >> sort[i];
        }
        
        insert_sort(sort, N);
        print(sort,N);
    }

}

void print(int *sort, int N)
{
    for(int i = 0; i < N; i++)
    {
        std::cout << sort[i];
        
        if(i != N - 1)
        {
            std::cout << " ";
        }
    }
    
    std::cout << std::endl;
}

void insert_sort(int *sort, int N)
{
    int v,j;
    for(int i = 1; i < N ; i++)
    {
        print(sort,N);
        v = sort[i];
        j = i - 1;
        
        while((j>=0) && (sort[j] > v))
        {
            sort[j+1] = sort[j];
            j--;
        }
        sort[j+1] = v;
    }
}


Measured memory_bytes: 3104
(defun solve (n k r s p hands)
  (declare (ignore n))
  (let ((lose (make-hash-table)))
    (loop for i from 0
          for h across hands
          if (and (<= k i)
                  (char= h (aref hands (- i k)))
                  (not (gethash (- i k) lose)))
          sum (progn (setf (gethash i lose) t) 0)
          else
          sum (ecase h
                (#\r p)
                (#\p s)
                (#\s r)))))

#-swank
(let ((n (read))
      (k (read))
      (r (read))
      (s (read))
      (p (read))
      (hands (read-line)))
  (format t "~A~%" (solve n k r s p hands)))


Measured memory_bytes: 15844
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int main()
{
	int n, i;
	cin >> n >> i;
	cout << (n-1)*(i-1) <<endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

class program
{
    public static void Main()
    {
        var strs = Console.ReadLine().Split(' ');
        var row = int.Parse(strs[0]);
        var column = int.Parse(strs[1]);

        int[,] table = new int[row + 1, column + 1];
        for (int i = 0; i < row; i++)
        {
            strs = Console.ReadLine().Split(' ');
            int sum = 0;
            for (int j = 0; j < column + 1; j++)
            {
                if (j < column)
                {
                    table[i, j] = int.Parse(strs[j]);
                    sum += table[i, j];
                }
                else
                {
                    table[i, j] = sum;
                }
            }
        }

        for (int i = 0; i < column + 1; i++)
        {
            int sum = 0;
            for (int j = 0; j < row + 1; j++)
            {
                if (j < row)
                {
                    sum += table[j, i];
                }
                else
                {
                    table[j, i] = sum;
                }
            }
        }

        for (int i = 0; i < row + 1; i++)
        {
            for (int j = 0; j < column + 1; j++)
            {
                Console.Write(table[i,j]);
                if (j < column) Console.Write(' ');
            }
            Console.WriteLine();
        }
    }
}

Measured memory_bytes: 20180
/*Bismillahir Rahmanir Rahim*/


#include<bits/stdc++.h>
#include<cstring>
#include<vector>
#include<map>
#include<set>
#define ll long long int
#define dd double
using namespace std;

int main()
{
   ll a,b;
   cin>>a;
     dd  ans=( dd)a/3,ans1;
     ans1=pow(ans,3);
   
    cout<<fixed<<setprecision(10)<<ans1<<endl;

}
//Apna Time Aayega :)

Measured memory_bytes: 4108
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {

  int X, Y;
  cin >> X >> Y;

  if(Y % 2 == 0 && Y >= 2 * X && Y <= 4 * X){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


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

int main() {
	string s;
	int maxi = 0, between, ans = 100000;
	cin >> s;

	for (char i = 'a'; i <= 'z' ; i++) {
		between = 0;
		maxi = 0;
		for (int j = 0; j< s.size(); j++) {
			if (s[j] == i) {
				maxi = max(maxi, between);
				between = 0;
			}
			else between++;
		}
		maxi = max(maxi, between);
		ans = min(maxi, ans);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
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;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<int> L(n); rep(i, n) cin >> L[i];
  sort(all(L));
  ll ans = 0;
  rep(i, n) REP(j, i+1, n) {
    ans += upper_bound(begin(L)+j, end(L), L[i]+L[j]-1) - (begin(L)+j) - 1;
  }
  cout << ans << endk;
  return 0;
}


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


#define li          long long int
#define uli         unsigned long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;



int main() {
    li n;
    string a,b;
    cin>>n;
    cin>>a>>b;
    rin{
        cout<<a[i]<<b[i];
    }
    cout<<endl;

    return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
#define mp make_pair
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
const ll INF=1LL<<30;
const ll LINF=1LL<<60;
const double eps=1e-5;
const ll MOD=1000000007LL;
template<typename T>void chmin(T &a,T b){a=min(a,b);};
template<typename T>void chmax(T &a,T b){a=max(a,b);};
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(){
    double t,x;cin>>t>>x;
    printf("%.10lf\n",t/x);
}


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

using std::bitset;

const int M=1e5+10,N=405;

int n,m,x[M],y[M];
bitset<N>q[N],P;

void Init() {
	scanf("%d%d",&n,&m);
	for (int i=0;i<m;++i) scanf("%d%d",&x[i],&y[i]),x[i]--,y[i]--;
}

void Solve() {
	for (int i=0;i<n;++i) P[i]=1;
	for (int i=0;i<n;++i) {
		q[i][i]=1;
		for (int j=m-1;j>=0;--j) {
			if (q[i][x[j]] && q[i][y[j]]) { q[i]=P; break; }
			if (q[i][x[j]]) q[i][y[j]]=1;
			else if (q[i][y[j]]) q[i][x[j]]=1;
		}
	}
	int cnt=0;
	for (int i=0;i<n;++i)
		for (int j=i+1;j<n;++j) 
			if ((q[i]&q[j]).count()==0) 
				cnt++;
	printf("%d\n",cnt);
}

int main() {
	Init();
	Solve();
	return 0;
}

Measured memory_bytes: 1024
import sys
from math import gcd
from functools import reduce
input = sys.stdin.buffer.readline

class FLT:
    def __init__(self, mod=10**9+7):
        self.mod = mod

    def rep_sqr(self, base, k):
        ans = 1
        while k > 0:
            if k & 1:
                ans = ans * base % self.mod
            base = base * base % self.mod
            k >>= 1
        return ans

    def inv(self, a):
        """ 逆元を取る """
        return self.rep_sqr(a, self.mod-2)


def gcd_list(numbers):
    return reduce(gcd, numbers)

def euler_phi(n):
    phi = n
    for i in set(prime_factorize(n)):
        phi *= (1 - (1 / i))
    return int(phi)

def prime_factorize(n):
    # Return list of prime factorized result
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

n, k = map(int, input().split())
MOD = 10**9 + 7
flt = FLT(MOD)
memo = [-1 for _ in range(k+1)]
ans = 0
for i in range(1, k+1):
    d = k // i
    ans += flt.rep_sqr(d, n) * euler_phi(i)
print(ans % MOD)

Measured memory_bytes: 75356
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <map>
#include <queue>
#include <stack>
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
using namespace std;
typedef long long ll;

int main(){
    int n = 6, a, b;
    cin >> a >> b;
    cout << n-a-b << endl;
    return 0;
}


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

int main(void){
    string a_str, b_str;
    cin >> a_str >> b_str;

    int a = atoi(a_str.c_str());
    int b = atoi(b_str.c_str());

    string a_str_con = "";
    string b_str_con = "";

    //連結
    for (int i = 1; i <= b; i++){
        a_str_con += a_str;
    }
    for (int i = 1; i <= a; i++){
        b_str_con += b_str;
    }

    if(a_str_con <= b_str_con){
        cout << a_str_con << endl;
    }
    else{
        cout << b_str_con << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cassert>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <sstream>
#include <istream>
#include <cmath>
#include <cstdio>
#include <complex>

using namespace std;

// figure
typedef long long ll;
typedef double D;

// repeat
#define for_(i, a, b) for (int i=a; i<b; i++)
#define for_d(i, b, a) for (int i=b-1; i>=a; i++)
#define FOR(it, c) for(__typeof((c).begin())it=(c).begin(); it!=(c).end(); it++)

// for STL
#define pb push_back
#define sz size()
#define all(x) x.begin(), x.end()
typedef vector<int> veci;
typedef vector<string> vecs;
typedef map<int, int> mapii;
typedef map<char, int> mapci;
typedef pair<int, int> P;

// memory
#define minit(a, i) memset(a, i, sizeof(a));

// inf
const int iINF = 2147483647;
const ll lINF = 9223372036854775807;

// eps
D EPS = 1e-9;

/***
 structure Point
 */
struct Point {
	D x, y;
	Point(D _x=0, D _y=0) : x(_x),y(_y) {}
};
typedef Point Vector;	// Point similar to Vector

// operator
Point operator + (const Point& a, const Point& b) { return Point(a.x+b.x, a.y+b.y); }
Point operator - (const Point& a, const Point& b) { return Point(a.x-b.x, a.y-b.y); }
Point operator * (const Point& a, const Point& b) { return Point(a.x*b.x, a.y*b.y); }
Point operator / (const Point& a, const Point& b) { return Point(a.x/b.x, a.y/b.y); }
bool operator < (const Point& a, const Point& b) { return a.x != b.x ? a.x < b.x : a.y < b.y; }
bool operator > (const Point& a, const Point& b) { return b.x != a.x ? b.x < a.x : b.y < a.y; }
bool operator == (const Point& a, const Point& b) { return fabs(a.x-b.x)<EPS && fabs(a.y-b.y)<EPS; }

// basic function
D norm(const Point& a) { return a.x*a.x + a.y*a.y; }
D dot(const Vector& a, const Vector& b) { return a.x*b.x + a.y*b.y; }
D cross(const Vector& a, const Vector& b) { return a.x*b.y - a.y*b.x; }
D dist(const Point& a, const Point& b) { return sqrt( (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y)); }
bool isVertical(const Vector& a, const Vector& b) { return fabs(dot(a,b))<EPS; }
bool isParrallel(const Vector& a, const Vector& b) { return fabs(cross(a,b))<EPS; }

struct Rectangle {
	D left, top, right, bottom;
	#define l left
	#define t top
	#define r right
	#define b bottom
	
	Rectangle (D _l=0, D _t=0, D _r=0, D _b=0):left(_l),top(_t),right(_r),bottom(_b) {}
};

// rectangle collision
bool rectCollision(Rectangle& A, Rectangle& B) {
	if (A.l <= B.r && A.b <= B.t && B.l <= A.r && B.b <= A.t) return true;
	return false;
}

int main() {
	Rectangle A, B;
	
	while (cin>>A.l>>A.b>>A.r>>A.t>>B.l>>B.b>>B.r>>B.t) {
		if (rectCollision(A, B)) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	
	return 0;
}

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

int main(void)
{
	string tem;
	
	while( cin>>tem )
	{
		if ( tem =="SUN")
			cout<<7<<endl;
		if ( tem =="MON")
			cout<<6<<endl;
		if ( tem =="TUE")
			cout<<5<<endl;		
		if ( tem =="WED")
			cout<<4<<endl;
		if ( tem =="THU")
			cout<<3<<endl;
		if ( tem =="FRI")
			cout<<2<<endl;
		if ( tem =="SAT")
			cout<<1<<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, m, q;
  cin >> n >> m >> q;
  vector<int> a(q), b(q), c(q), d(q);
  for (int i = 0; i < q; i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    a[i]--, b[i]--;
  }
  vector<int> h(n + m - 1, 1);
  for (int i = 0; i < m - 1; i++) {
    h[i] = 0;
  }
  int ans = 0;
  do {
    vector<int> A;
    int cnt = 1;
    for (auto&& e : h) {
      if (e == 0) {
        cnt++;
      } else {
        A.push_back(cnt);
      }
    }
    int score = 0;
    for (int i = 0; i < q; i++) {
      if (A[b[i]] - A[a[i]] == c[i]) {
        score += d[i];
      }
    }
    ans = max(ans, score);
  } while (next_permutation(h.begin(), h.end()));
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3656
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cmath>
#include<bitset>
typedef long long ll;
#define PB	push_back
#define FOR(n)			for(int i = 0; i < n; ++i)
#define RFOR(n)			for(int i = n; i >= 0; --i)
#define FORR(start,end) for(int i = start; i < end; ++i)
#define COUT(n)			cout << n << " " << flush
#define vi(v)			vector<int> v
#define vii(v)			vector<pair<int,int>> v
#define pii(p)			pair<int,int> p
#define mii(m)			map<int, int> m
#define msi(m)			map<string, int, less<>> m
#define mmsi(m)			multimap<string, int, less<>> m
#define mkp(a,b)		make_pair(a,b)
#define ALL(obj)		obj.begin(), obj.end()
#define PI 3.141592
#define MOD 1e9+7
using namespace std;

void solve() {
	string s, t, u;
	int a, b;
	cin >> s >> t;
	cin >> a >> b;
	cin >> u;
	if (u == s)
		a -= 1;
	else
		b -= 1;
	cout << a << ' ' << b << endl;
}

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>

using namespace std;

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b&&b==c){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}


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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  vll a(n);
  rep(i,n) cin>>a[i];
  
  deque<ll> d;
  rep(i,n){
    auto itr=lower_bound(all(d),a[i]);
    if(itr==d.begin()){
      d.push_front(a[i]);
    }else{
      ll j=itr-d.begin();
      j--;
      d[j]=a[i];
    }
  }
  cout<<d.size()<<endl;
}


Measured memory_bytes: 1920
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <map>
#include <string>
#include <math.h>

using namespace std;

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

    int rui = 1;
    for (int i = 0; i < N - 1; i++)
    {
        rui *= K - 1;
    }

    cout << K * rui << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ll long long 
#define pb push_back
#define mk make_pair
#define mod 1e9+7
using namespace std;

ll gcd(ll a, ll b){
    return __gcd(a,b);
}

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

bool isPrime(ll n){
    if(n <= 1) return false;
    for(ll i=2; i<=sqrt(n); i++){
        if(n%i == 0){
            return false;
        }
    }
    return true;
}

void solve(){
    string a,b;
    cin >> a >> b;
    ll res = 0;
    for(ll i=0; i<a.length(); i++) {
        if(a[i]!=b[i]) res++;
    }
    cout << res << endl;
}

int main() {
    fast;
    solve();
	//ll t; cin >> t; while(t--){ solve(); }
	return 0;
}

Measured memory_bytes: 3832
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define gc getchar_unlocked()
#define pc(x) putchar_unlocked(x)
template<typename T> void scan(T &x){x = 0;bool _=0;T c=gc;_=c==45;c=_?gc:c;while(c<48||c>57)c=gc;for(;c<48||c>57;c=gc);for(;c>47&&c<58;c=gc)x=(x<<3)+(x<<1)+(c&15);x=_?-x:x;}
template<typename T> void printn(T n){bool _=0;_=n<0;n=_?-n:n;char snum[65];int i=0;do{snum[i++]=n%10+48;n/= 10;}while(n);--i;if (_)pc(45);while(i>=0)pc(snum[i--]);}
template<typename First, typename ... Ints> void scan(First &arg, Ints&... rest){scan(arg);scan(rest...);}
template<typename T> void print(T n){printn(n);pc(10);}
template<typename First, typename ... Ints> void print(First arg, Ints... rest){printn(arg);pc(32);print(rest...);}

using namespace std;
using ll = long long;
const int MM = 1e5+5;

int n;
ll a[3];
string s;
int fir[MM], sec[MM];
vector<char> out;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    cin>>n>>a[0]>>a[1]>>a[2];
    
    if(a[0]+a[1]+a[2] == 0){
        return cout<<"No\n", 0;
    }
    
    for(int i = 1; i <= n; i++){
        cin>>s;
        fir[i] = s[0]-'A';
        sec[i] = s[1]-'A';
    }
    
    for(int i = 1; i <= n; i++){
        int b = fir[i], c = sec[i];
        
        if(a[b]+a[c] == 0)
            return cout<<"No\n", 0;
        
        if(a[b] == 1 and a[c] == 1 and i != n){
            //check next one
            set<int> st;
            st.insert(fir[i+1]);
            st.insert(sec[i+1]);
            
            if(st.count(b)){
                a[c]--, a[b]++;
                out.push_back(b+'A');
            }
            else{
                a[b]--, a[c]++;
                out.push_back(c+'A');
            }
        }
        else if(a[b] > a[c]){
            a[b]--, a[c]++;
            out.push_back(c+'A');
        }
        else{
            a[c]--, a[b]++;
            out.push_back(b+'A');
        }
    }
    cout<<"Yes\n";
    for(char c: out)
        cout<<c<<'\n';
    
    
    return 0;
}
/*
2 1 1 0
AB
BC

2 1 1 0
AB
AC
 */

Measured memory_bytes: 4532
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <ctime>
#include <cmath>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;

#define sz(x) (int)(x.size())

typedef long long ll;
typedef tuple<int, int, int> tri;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef __gnu_pbds::tree<
    int,
    __gnu_pbds::null_type,
    less<int>,
    __gnu_pbds::rb_tree_tag,
    __gnu_pbds::tree_order_statistics_node_update>
    ordered_set;

const ll MODULO = 1000000007;

void ftime()
{
#ifndef ONLINE_JUDGE
    cout << "\nTime: " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
#endif
}

static int speed_increase = []() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(NULL);
    return 0;
}();

void solve()
{
    int n;
    cin >> n;
    vll a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    sort(a.begin(), a.end());
    ll cnt = 0;
    for (int i = n - 1; i >= 0; --i)
    {
        for (int j = i - 1; j >= 0; --j)
        {
            for (int k = j - 1; k >= 0; --k)
            {
                if (a[j] == a[i] || a[k] == a[j])
                    continue;
                if(a[i] < a[j] + a[k]) {
                    ++cnt;
                }
            }
        }
    }
    cout << cnt;
}

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

Measured memory_bytes: 3656
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <utility>

int main(){
  int x[5];
  bool used[6];
  for (int i=0; i<6; i++){
    used[i]=false;
  }
  for (int i=0; i<5; i++){
    scanf("%d", &x[i]);
    used[x[i]]=true;
  }
  for (int i=1; i<=5; i++){
    if (!used[i]) printf("%d\n", i);
  }
  return 0;
}


Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
int main(){long long x,a,k,d;cin>>x>>k>>d;
        if((abs(x)>k*d)&&(((k*d)%1000000007-(k%1000000007)*(d%1000000007))%1000000007==0)){if(x>0)a=abs(x-k*d);else a=abs(k*d+x);}
else {if(k%2==1){k--;if(x>0)x-=d;else x+=d;}d*=2;
   if(abs(x%d)<d-abs(x%d))a=abs(x%d);else a=d-abs(x%d);}
cout<<a<<endl;}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>

using namespace std;

int H, W;
int ans = 0;
int INF = 10000000;
int a[1001][1001];
int memo[1001][1001];

int a_(int i, int j){
	if(i < 0 || j < 0 || i >= H || j >= W){
		return INF;
	}
	return a[i][j];
}

int search(int i, int j){
	if(i < 0 || j < 0 || i >= H || j >= W){
		return -1;
	}
	if(memo[i][j] > 0){
		return memo[i][j];
	}
	int cnt = 0;
	int num = 0;
	if(a_(i, j) > a_(i - 1, j)){
		int ret = search(i - 1, j);
		if(ret > 0){
			cnt++;
			if(num == ret){
				cnt--;
			}
			num = ret;
		}
	}
	if(a_(i, j) > a_(i + 1, j)){
		int ret = search(i + 1, j);
		if(ret > 0){
			cnt++;
			if(num == ret){
				cnt--;
			}
			num = ret;
		}
	}
	if(a_(i, j) > a_(i, j - 1)){
		int ret = search(i, j - 1);
		if(ret > 0){
			cnt++;
			if(num == ret){
				cnt--;
			}
			num = ret;
		}
	}
	if(a_(i, j) > a_(i, j + 1)){
		int ret = search(i, j + 1);
		if(ret > 0){
			cnt++;
			if(num == ret){
				cnt--;
			}
			num = ret;
		}
	}
	if(cnt == 0){
		num = a[i][j];
	}
	if(cnt > 1){
		num = INF;
	}
	memo[i][j] = num;
	if(num == INF){
		ans++;
	}
	return num;
}

int main(){
	
	cin >> H >> W;
	
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			cin >> a[i][j];
			memo[i][j] = -1;
		}
	}
	
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			if(memo[i][j] == -1){
				search(i, j);
			}
		}
	}
	/*
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			cout << memo[i][j] << " ";
		}
		cout << endl;
	}
	*/
	cout << ans << endl;
	
	return 0;
}



Measured memory_bytes: 42020
import java.util.*;

/**
 * Created by Santa.
 */
public class Main {

    static int N;
    static int M;
    static int A;
    static long B;
    static long C;
//    static int[][] map;
    static int min = 9999999;
    static int[] moto = new int[3];

    static class pair implements Comparable{
            public int a;
            public int b;

            pair(){
                this.a = 0;
                this.b = 0;
            }

            pair(int a, int b){
                this.a = a;
                this.b = b;
            }

            public void set(int a, int b) {
                this.a = a;
                this.b = b;
            }

        @Override
        public int compareTo(Object o) {
            pair aite = (pair)o;

            if(this.b > aite.b)return 1;
            if(this.b < aite.b)return -1;
            return  0;
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        N = scanner.nextInt();
        M = scanner.nextInt();

        pair[] map = new pair[M];

        for (int i = 0; i < M; i++) {
            map[i] = new pair();
            map[i].a = scanner.nextInt();
            map[i].b = scanner.nextInt();
        }

        Arrays.sort(map);
//        System.out.println(map[0].a);

//        for (int i = 0; i < M; i++) {
//            System.out.println(map[i].a + " == " + map[i].b);
//        }

        int ans = 0;

        for (int i = 0; i < M; i++) {
            ans++;
            int now = map[i].b;
//            System.out.println(now);
            while(true){
                if(i >= M || map[i].a >= now){
//                    System.out.println("asdf");
                    i--;
                    break;
                }
                i++;
            }
        }

        System.out.println(ans);



    }




}



Measured memory_bytes: 89324
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define DEKAI 2000000000
#define MAX 100000

struct Card
{
	char suit;
	int value;
};


Card L[MAX/2+2],R[MAX/2+2];

void merge(struct Card A[],int left,int mid,int right)
{
	int n1 = mid - left;
	int n2 = right - mid;
	for (int i = 0; i < n1; ++i)
	{
		L[i] = A[left + i];
	}
	for (int i = 0; i < n2; ++i)
	{
		R[i] = A[mid + i];
	}
	L[n1].value = R[n2].value = DEKAI;
	int i = 0;
	int j = 0;
	for (int k = left; k < right ; ++k)
	{
		if (L[i].value <= R[j].value)
		{
			A[k] = L[i];
			i++;			
		}
		else
		{
			A[k] = R[j];
			j++;
		}
	}
}

void mergesort(struct Card A[],int left,int right)
{
	if (left+1 < right)
	{
		int mid = (left + right)/2;
		mergesort(A,left,mid);
		mergesort(A,mid,right);
		merge(A,left,mid,right);
	}
}

int partition(struct Card A[],int p,int r)
{
	Card x = A[r];
	int i = p-1;
	for (int j = p; j < r; ++j)
	{
		if (A[j].value <= x.value)
		{
			i++;
			swap(A[i],A[j]);
		}
	}
	swap(A[i+1],A[r]);
	return i+1;
}

void quickSort(struct Card A[],int p,int r)
{
	int q;
	if (p < r)
	{
		q = partition(A,p,r);
		quickSort(A,p,q-1);
		quickSort(A,q+1,r);
	}
}

int main()
{
	int n,v;
	Card A[MAX],B[MAX];
	int stable = 1;
	char S[100];
	scanf("%d",&n);
	for (int i = 0; i < n; ++i)
	{
		scanf("%s %d",&S,&v);
		A[i].suit = B[i].suit = S[0];
		A[i].value = B[i].value = v;
	}

	mergesort(A,0,n);
	quickSort(B,0,n-1);

	//??????
	for (int i = 0; i < n; ++i)
	{
		if (A[i].suit != B[i].suit)
		{
			stable = 0;
		}
	}

	if (stable)
	{
		printf("Stable\n");
	}
	else
	{
		printf("Not stable\n");
	}
	for (int i = 0; i < n; ++i)
	{
		printf("%c %d\n",B[i].suit,B[i].value);
	}
	return 0;
}


Measured memory_bytes: 5540
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
B = [int(x) for x in input().split()]

A = [B[0]] + [min(B[i-1],B[i]) for i in range(1,N-1)] + [B[-1]]

answer = sum(A)
print(answer)

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

#define OUT(x)  cerr << #x << " = " << x << endl;
#define all(x)  x.begin(), x.end()
#define mp      make_pair
#define pii     pair<int, int>
#define piii    pair<int, pair<int, int>>

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

int main() {
        int n;
        cin >> n;
        long long ans = 1;
        for (int i = 0; i < n; i ++) {
                long long a;
                cin >> a;
                ans = lcm(ans, a);
        }
        cout << ans << endl;
        return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  int N;
  cin >> N;
  vector<int> A(N + 1);
  vector<int> B(N);
  for (int i = 0; i < N + 1; ++i) {
    cin >> A[i];
  }
  for (int i = 0; i < N; ++i) {
    cin >> B[i];
  }

  ll num_mon = 0;
  for (int i = N - 1; i != -1; --i) {
    // i+1からアタックする
    if (A[i + 1] > B[i]) {
      num_mon += B[i];
      continue;
    } else if (A[i + 1] <= B[i]) {
      num_mon += A[i + 1];
      B[i] = B[i] - A[i + 1];

      // iへアタックする
      if (A[i] > B[i]) {
        num_mon += B[i];
        A[i] = A[i] - B[i];
      } else if (A[i] <= B[i]) {
        num_mon += A[i];
        A[i] = 0;
      }
    }
  }
  cout << num_mon << endl;
  return 0;
}


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

typedef long long ll;
const ll INF = (ll)1 << 60;

int main() {
  int n;
  ll a, b;
  cin >> n >> a >> b;
  ll x[n];
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  ll dp[2];
  dp[0] = 0;
  for (int i = 1; i < n; i++) {
    dp[i % 2] =
        min(dp[(i - 1) % 2] + (x[i] - x[i - 1]) * a, dp[(i - 1) % 2] + b);
  }
  cout << dp[(n - 1) % 2] << endl;
}


Measured memory_bytes: 1024
n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0

for i in range(n):
    tmp = A[i] - B[i]
    if tmp < 0 and -tmp <= A[i+1]:
        A[i+1] += tmp
        ans += B[i]
    elif tmp < 0 and -tmp > A[i+1]:
        ans += A[i] +A[i+1]
        A[i+1] = 0
    elif tmp >= 0:
        ans += B[i]

print(ans)

Measured memory_bytes: 18624
def solve(string):
    n = len(string)
    pre, post = string[:(n - 1) // 2], string[(n + 3) // 2 - 1:]
    return "Yes" if string == string[::-1] and pre == pre[::-1] and post == post[::-1] else "No"


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <ctime>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <queue>
#include <utility>
#include <cmath>
#include <functional>
#include <map>
#include <set>
const int INF = 1000000009;

int n, m;
typedef std::pair<int, int> P;
std::vector<P> know[100000];
int pos[100000];
bool used[100000];

bool fill(int a, int p){
	if(used[a] == true){
		if(pos[a] == p){
			return true;
		}else{
			return false;
		}
	}else{
		used[a] = true;
		pos[a] = p;
		for(int i = 0; i < know[a].size(); i++){
			if(fill(know[a][i].first, p + know[a][i].second) == false){
				return false;
			}
		}
		return true;
	}
}

int main(){
	scanf("%d%d", &n, &m);
	for(int i = 0; i < m; i++){
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		a--;
		b--;
		know[a].push_back(P(b, c));
		know[b].push_back(P(a, -c));
	}
	for(int i = 0; i < n; i++){
		pos[i] = INF;
	}
	for(int i = 0; i < n; i++){
		if(!used[i]){
			if(!fill(i, 0)){
				printf("No\n");
				return 0;
			}
		}
	}
	printf("Yes\n");
	return 0;
}


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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;


int main(){

    int n, m;
    cin >> n >> m;
    cout << (n-1)*(m-1) << endl;

    return 0;
}

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

#define _GLIBCXX_DEBUG

//vector<int> A(M), B(M);
//vector<vector<char>> answer(N, vector<char>(N, '-'));

int main() {
  int r;
  int ans;
  
  cin >> r;
  
  ans = 3*r*r;
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  string s;
  cin >> s;
  int ans = 0;
  rep(i,3) {
    if(s[i]!='R') continue;
    srep(j,i,3) {
      if(s[j]!='R') break;
      chmax(ans,j-i+1);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3620
a,b,c,d,e,f,v,w,s,t;float p,u=1;I(x,y){a-=x,b-=y;c-=x,d-=y;e-=x,f-=y;p=u*c*f-u*d*e;return(u*a*d-u*b*c)*p>0&p*(u*e*b-u*f*a)>0;}main(i){for(;~scanf("%*d%d%d%d%d%d%d%d%d%d%d"+!!p*3,&a,&b,&c,&d,&e,&f,&v,&w,&s,&t);puts(i^I(s-v,t-w)?"OK":"NG"))i=I(v,w);}

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

using _i64 = int64_t;
using _u64 = uint64_t;
using _f64 = double;

#define endl "\n"

#define _for(i, start, end) for(_i64 i = (_i64)start; i < (_i64)end; ++i)
#define _rep(i, number) _for(i, 0, number)
#define _foreach(e, data) for(auto& e : data)
#define _all(data) data.begin(), data.end()

template<typename type>
_i64 _size(const type& data) { return static_cast<_i64>(data.size()); }
template<typename type, size_t size>
_i64 _size(const type (&)[size]) { return static_cast<_i64>(size); }

enum _flag : bool { able = true, disable = false };

struct _time {
    _time(_flag flag) { check = flag; if(!check) { return; } gettime(start); }
    ~_time() {
        if(!check) { return; }; gettime(end);
        _i64 elapse = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cout << endl << "Time: " << elapse << " ms" << endl;
    }
    private:
    using _timer = chrono::time_point<chrono::system_clock>;
    _timer start, end; bool check;
    void gettime(_timer& time) { time = chrono::system_clock::now(); }
};

struct _ini { _ini() { ios::sync_with_stdio(false); cin.tie(nullptr); } } _ini;

struct _vector2 {
    _f64 x, y;
    _vector2 operator+(const _vector2& rhs) const {
        _vector2 temp;
        temp.x = x + rhs.x; temp.y = y + rhs.y;
        return temp;
    }
    _vector2 operator-(const _vector2& rhs) const {
        _vector2 temp;
        temp.x = x - rhs.x; temp.y = y - rhs.y;
        return temp;
    }
};

int main() {
    {
        _time time(disable);
        _vector2 OA, OB, OC, OP, AP, BP, CP; bool ans1, ans2;
        auto outer2 = [](_vector2 v1, _vector2 v2) -> _f64 { return v1.x * v2.y - v1.y * v2.x; };
        while(cin >> OA.x >> OA.y >> OB.x >> OB.y >> OC.x >> OC.y >> OP.x >> OP.y) {
            AP = OP - OA; BP = OP - OB; CP = OP - OC;
            ans1 = outer2(AP, BP) > 0 && outer2(BP, CP) > 0 && outer2(CP, AP) > 0;
            ans2 = outer2(AP, BP) < 0 && outer2(BP, CP) < 0 && outer2(CP, AP) < 0;
            cout << (ans1 || ans2 ? "YES" : "NO") << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3216
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <ctime>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

ll n,k;
vl a(101010), b(101010);

ll rec(ll x){
	ll res = 0;
	if(x == 0){
		rep(i,n){
			if(a[i] == 0) res += b[i];
		}
		return res;
	}
	ll p = 0;
	while(1<<p <= x) p++;
	p--;
	rep(i,n){
		if(a[i] > x) continue;
		else if(a[i]>>p & 1) a[i] -= 1<<p;
		else res += b[i];
	}
	chmax(res, rec(x - (1<<p)));
	return res;
}

int main(){
	cin >> n >> k;
	rep(i,n) cin >> a[i] >> b[i];
	cout << rec(k) << endl;
}

Measured memory_bytes: 1920
#include <stdio.h>

long N;
long W;
long dp[101][100001];
long w[101];
long v[101];
//dpに格納するのは重さの総和
//価値の総和は配列の要素番号
long V = 100001;
const long INF = 1000000001; 
long min(long a, long b)
{
	if (a > b) return b;
	return a;
}

int main(int argc, char const *argv[])
{
	scanf("%ld%ld", &N, &W);
	for (int i = 0; i < N; i++) scanf("%ld%ld", w+i, v+i);
	for (int i = 0; i < 101; i++) for (int j = 0; j < V; j++) dp[i][j] = INF;
	dp[0][0] = 0;
	for (long i = 0; i < N; i++) for (long j = 0; j < V; j++)
		{
			if (j + v[i] < V) dp[i+1][j + v[i]] = min(dp[i+1][j + v[i]], dp[i][j] + w[i]);
			dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
		}
	long res = 0;
	for (long j = 0; j < V; j++) if(dp[N][j] <= W) res = j;

	printf("%ld", res);
	return 0;
}


Measured memory_bytes: 79104