akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

const int vy[] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int vx[] = {-1, 0, 1, 1, 1, 0, -1, -1};

string S[19];
int sx, sy;

bool isgoal(int y, int x)
{
  return ((y == 18 && 0 <= x && x <= 14) || y == 19);
}

int bfs()
{
  map< tuple< int, int, int >, int > v;
  queue< tuple< int, int, int > > que;
  que.emplace(0, sy, sx);
  v[que.front()] = 0;
  while(!que.empty()) {
    auto p = que.front();
    int bit, y, x;
    tie(bit, y, x) = p;
    que.pop();
    for(int i = 0; i < 8; i++) {
      int ny = vy[i] + y, nx = vx[i] + x, bb = bit;
      while(nx >= 0 && nx < 15 && ny >= 0 && ny < 19 && S[ny][nx] < 20) {
        if((bit >> S[ny][nx]) & 1) break;
        bb |= 1 << S[ny][nx];
        ny += vy[i], nx += vx[i];
      }
      if(ny == vy[i] + y && nx == vx[i] + x) continue;
      if(isgoal(ny, nx)) return (v[p] + 1);
      if(ny >= 0 && nx < 15 && ny >= 0 && ny < 19) {
        auto nxt = make_tuple(bb, ny, nx);
        if(v.count(nxt) && v[nxt] <= v[p] + 1)continue;
        v[nxt] = v[p] + 1;
        que.emplace(nxt);
      }
    }
  }
  return (-1);
}

int main()
{
  int pad = 0;
  for(int i = 0; i < 19; i++) {
    cin >> S[i];
    for(int j = 0; j < 15; j++) {
      if(S[i][j] == 'X') S[i][j] = pad++;
      else if(S[i][j] == 'O') sy = i, sx = j;
    }
  }
  cout << bfs() << endl;
}

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

void call(int n){
  int i = 1;
  do{
    int x = i;
    if ( x % 3 == 0 ){
      cout << " " << i;
      continue;
    }
    do{
      if ( x % 10 == 3 ){
        cout << " " << i;
        break;
      }
      x /= 10;
    }while( x );
  }while ( ++i <= n );
  cout << endl;
}

int main(void){
	int x;
	cin >> x;
	call(x);
	return 0;
}

Measured memory_bytes: 3088
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.numeric;


void main()
{
  auto x = readln.chomp.to!long;
  auto t = x % 11;
  auto res = (x / 11) * 2;
  if (t > 6) {
    res += 2;
  } else if (t > 0) {
    res += 1;
  }
  res.writeln;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define si(v) int(v.size())
#define len(v) int(v.length())
#define lob(v,n) lower_bound(all(v),n)
#define lobi(v,n) lower_bound(all(v),n) - v.begin()
#define upb(v,n) upper_bound(all(v),n)
#define upbi(v,n) upper_bound(all(v),n) - v.begin()
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vc = vector<char>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vvp = vector<vector<pair<int,int>>>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}

struct UnionFind {
    vector<int> root;
    
    UnionFind(int n) {
        root.assign(n,-1);
    }
    
    int find(int n){
        if(root[n] < 0) return n;
        else return root[n] = find(root[n]);
    }
    
    void connect(int a,int b){
        int ar = find(a);
        int br = find(b);
        if(ar == br) return;
        
        if(-root[ar] < -root[br]){
            root[br] += root[ar];
            root[ar] = br;
        }else{
            root[ar] += root[br];
            root[br] = ar;
        }
    }
    
    
};


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

    int N,M;
    cin >> N >> M;
    
    UnionFind U(N);
    rep(i,M){
        int a,b;
        cin >> a >> b;
        a--,b--;
        U.connect(a,b);
    }
    map<int,int> A;
    rep(i,N) A[U.find(i)]++;
    int ans = 0;
    for (auto p : A) {
        chmax(ans,p.se);
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 13412
/*
useful stl
array<ll,size> ar;         //size(),front(),back(),fill(),empty()
deque<ll> d                //push_back(),push_front(),pop_front(),pop_back()
vector<ll> v(size,val);    //push_back(),*max_element(v.begin(),v.end()),accumulate(v.begin(),v.endaa(),0),pop_back()
stack<ll> g;               //push(),pop(),top(),size(),empty()         LIFO
queue<ll> q;               //push(),size(),front(),back(),empty()      FIFO
priority_queue<ll> pq
*/
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; 

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

    long long n, ans=0;
    cin>>n;
    vector<long long>v(n+1);
    map<long long,long long>mp;
    for(int i=1;i<=n;i++)
    {
        cin>>v[i];
        ans +=mp[v[i]-i];
        mp[-i-v[i]]++;
    }
    cout<<ans;

    return 0;
}

Measured memory_bytes: 27436
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define ld double 
#define rep(i,a,b) for(ll i=a; i<b; ++i)
#define BOOST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(v) v.begin(),v.end()
#define sl(a) a.size()
#define mod 1000000007 
#define lcm(a,b) (a*b)/__gcd(a,b)
#define MAX1 100006
#define f first
#define s second
#define pi 2*acos(0.0)
void solve()
{
    ll n,count=0;  cin>>n;
    ll arr[n];
    rep(i,0,n)  cin>>arr[i];
    sort(arr,arr+n);
    rep(i,0,n)  
    {
        rep(j,i+1,n)
        {
            rep(k,j+1,n) 
            {
                ll a=arr[i],b=arr[j],c=arr[k];
                if(arr[i]+arr[j]>arr[k] and a!=b and b!=c and c!=a) count++;
            }
        }
    }cout<<count<<"\n";
}
int main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt","r",stdin);
    // for writing output to output.txt
    freopen("output.txt","w",stdout);
    #endif
    BOOST
    int T=1;  //cin>>T;
    while(T--) solve();
    return 0;
}


Measured memory_bytes: 3656
#include<stdio.h>
#include<stdlib.h>
int cnt;

void swap(int *x, int *y)
{
  int tmp;

  tmp = *x;
  *x = *y;
  *y = tmp;
 
}


void insertionSort(int *A, int N, int g)
{
  int i,j;
  int v;
  for(i=g; i<N; i++) {
    v = A[i];
    j = i - g;
    while(j >= 0 && A[j] > v){
      A[j+g] = A[j];
      j -= g;
      cnt++;
    }
    A[j+g] = v;

    //    for(j=0; j<N-1; j++)
    //      printf("%d ", A[j]);
    //    printf("%d\n", A[N-1]);
  }
}

void shellSort(int *A, int n, int *G, int m)
{
  int cnt = 0, i;
  for (i = m-1; i>=0; i--) {
    insertionSort(A, n, G[i]);
  }
}

int main(void)
{
  int *A, N, i;
  int m = 2;
  int G[100];
  
  scanf("%d",&N);
  A = (int *) calloc(N, sizeof(int));
  
  for(i=0;i<N;i++) {
    scanf("%d", &A[i]); //配列読み込み
  }    

  G[0] = 1;
  for (m = 1; G[m-1] <= N; m++){
    G[m] = 3*G[m-1]+1;
  }
  m -= 1;
    
  cnt = 0;
  shellSort(A, N, G, m);

  // m を出力
  printf("%d\n", m);
  // G を出力
  for(i=m-1; i>0; i--)
    printf("%d ", G[i]);
  printf("%d\n", G[0]);
  // cnt を出力
  printf("%d\n", cnt);

  // A を出力
  for(i=0; i<N; i++){
    printf("%d\n", A[i]);
  }

  return 0;
}

  



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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	sort(all(a));
	map<int, int> mp;
	rep(i, n) mp[a[i]]++;
	
	int ans = 0;
	int cnt2 = 0;
	for(auto t: mp) {
		int k = t.first;
		int v = t.second;
		if(v >= 3) v = (v+1)%2 + 1;
		if(v == 2) cnt2++;
		ans += v;
	}
	if(cnt2%2 == 0) {
		ans -= cnt2;
	} else {
		ans -= cnt2 + 1;
	}
	// if(ans < 1) ans = 1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5376
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <fstream>

using namespace std;
typedef pair<int,int> pii;

int h,w,s;
pii dp[32][32][32][32];
int field[32][32];
int sumTbl[32][32];
int allSum;

pii dfs(int minx,int miny,int maxx,int maxy){
	if(dp[minx][miny][maxx][maxy].first!=-1)return dp[minx][miny][maxx][maxy];
	int sum=0;
	for(int i=miny;i<=maxy;i++){
		if(minx==0)sum+=sumTbl[i][maxx];
		else sum+=sumTbl[i][maxx]-sumTbl[i][minx-1];
	}
	pii res(1,sum);
	for(int i=miny;i<maxy;i++){
		int sum1=0;
		int sum2=0;
		for(int j=miny;j<=i;j++){
			if(minx==0)sum1+=sumTbl[j][maxx];
			else sum1+=sumTbl[j][maxx]-sumTbl[j][minx-1];
		}
		for(int j=i+1;j<=maxy;j++){
			if(minx==0)sum2+=sumTbl[j][maxx];
			else sum2+=sumTbl[j][maxx]-sumTbl[j][minx-1];
		}
		if(allSum-sum1<=s&&allSum-sum2<=s){
			pii p1=dfs(minx,miny,maxx,i);
			pii p2=dfs(minx,i+1,maxx,maxy);
			if(res.first<p1.first+p2.first){
				res.first=p1.first+p2.first;
				res.second=min(p1.second,p2.second);
			}
			else if(res.first==p1.first+p2.first)
				res.second=max(res.second,min(p1.second,p2.second));
		}
	}
	for(int i=minx;i<maxx;i++){
		int sum1=0;
		int sum2=0;
		for(int j=miny;j<=maxy;j++){
			if(minx==0)sum1+=sumTbl[j][i];
			else sum1+=sumTbl[j][i]-sumTbl[j][minx-1];
		}
		for(int j=miny;j<=maxy;j++)sum2+=sumTbl[j][maxx]-sumTbl[j][i];
		if(allSum-sum1<=s&&allSum-sum2<=s){
			pii p1=dfs(minx,miny,i,maxy);
			pii p2=dfs(i+1,miny,maxx,maxy);
			if(res.first<p1.first+p2.first){
				res.first=p1.first+p2.first;
				res.second=min(p1.second,p2.second);
			}
			else if(res.first==p1.first+p2.first)
				res.second=max(res.second,min(p1.second,p2.second));
		}
	}
	return dp[minx][miny][maxx][maxy]=res;
}

int main(){
	while(cin>>h>>w>>s&&(h|w|s)){
		allSum=0;
		for(int i=0;i<32;i++)for(int j=0;j<32;j++)
				for(int k=0;k<32;k++)for(int l=0;l<32;l++)dp[i][j][k][l].first=dp[i][j][k][l].second=-1;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				cin>>field[i][j];
				allSum+=field[i][j];
			}
		}
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(j==0)sumTbl[i][j]=field[i][j];
				else sumTbl[i][j]=sumTbl[i][j-1]+field[i][j];
			}
		}
		pii res=dfs(0,0,w-1,h-1);
		cout<<res.first<<" "<<s-(allSum-res.second)<<endl;
	}
	return 0;
}

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


ll combination(ll n, ll r){
    if(n < r) return 0;
    if(r == 0||r == n) return 1;
    else if(r == 1) return n;
    return (combination(n - 1, r - 1) + combination(n - 1, r));
}

bool checkKaibun(string str){
    string checkStr = str;
    reverse(checkStr.begin(), checkStr.end());
    if(str == checkStr) return true;
    else return false;
}

int keta(ll num){
    int digits = 0;
    while(num > 0){
        num /= 10;
        digits++;
    }
    return digits;
}


int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    vector<vector<int>> x(N, vector<int>(N - 1)), y(N, vector<int>(N - 1));
    rep(i, N){
        cin >> A.at(i);
        rep(j, A.at(i)){
            cin >> x.at(i).at(j) >> y.at(i).at(j);
        }   
    }
    //すべての組み合わせを調べる 2^15= 32678くらいで余裕
    int ans = 0;
    for(int bit = 0; bit < (1 << N); bit++){
        bitset<15> s(bit);
        bool flag = true;
        rep(i, N){//すべての人間に関して矛盾が生じていないか調べる？
            int num = A.at(i);
            bool honest = s.test(i);
            rep(j, num){
                bool testHonest = s.test(x.at(i).at(j) - 1);
                if(honest == 1){
                    if(testHonest != y.at(i).at(j)) flag = false;
                }
            }
        }
        if(flag == true){
            int sum = 0;
            rep(j, N) sum += s.test(j);
            ans = max(sum, ans);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vp;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
const ll INF=99999999999999999;
ll a,b,c,d,e,f,ans=0;
int main(){
    ll n;
    cin>>n;
    ll t[4][4][4][4];
    ll memo[4][4][4][4];
    if(n==3)cout<<61<<endl;
    if(n>3){
        for(int i=0;i<4;i++){
            for(int j=0;j<4;j++){
                for(int k=0;k<4;k++){
                    for(int l=0;l<4;l++){
                    if((i==0&&j==2&&k==1)||(i==2&&j==0&&k==1)||(i==0&&j==1&&k==2)||(i==0&&k==2&&l==1)||(i==0&&j==2&&l==1)||(j==0&&k==2&&l==1)||(j==0&&k==1&&l==2)||(j==2&&k==0&&l==1))t[i][j][k][l]=0;
                    else t[i][j][k][l]=1;
                    
                }
            }
        }
    }

    for(int x=0;x<n-4;x++){
        for(int i=0;i<4;i++){
            for(int j=0;j<4;j++){
                for(int k=0;k<4;k++){
                    for(int l=0;l<4;l++){
                    if((i==0&&j==2&&k==1)||(i==2&&j==0&&k==1)||(i==0&&j==1&&k==2)||(i==0&&k==2&&l==1)||(i==0&&j==2&&l==1)||(j==0&&k==2&&l==1)||(j==0&&k==1&&l==2)||(j==2&&k==0&&l==1))memo[i][j][k][l]=0;
                    else memo[i][j][k][l]=(t[0][i][j][k]+t[1][i][j][k]+t[2][i][j][k]+t[3][i][j][k])%1000000007;
                    
                }
            }
        }
    }
      for(int i=0;i<4;i++){
            for(int j=0;j<4;j++){
                for(int k=0;k<4;k++){
                    for(int l=0;l<4;l++){
                    t[i][j][k][l]=memo[i][j][k][l];                   
                }
            }
        }
    }
    }

    for(int i=0;i<4;i++){
            for(int j=0;j<4;j++){
                for(int k=0;k<4;k++){
                    for(int l=0;l<4;l++){
                    ans=(ans+t[i][j][k][l])%1000000007;
                }
            }
        }
    }

    cout<<ans<<endl;

    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
template<class T>
void dump(vector<T> &vec){
	for(int i=0;i<vec.size();i++){
		cout << vec[i];
		if(i+1<vec.size())cout << ' ';
		else cout << endl;
	}
	return;
}
int N,K;
string s;
int main(){
	cin >> N >> K;
	cin >> s;
	int ans = 1;
	for(int i=0;i<N;i++){
		if(i>0&&s[i]!=s[i-1])ans++;
	}
	// cout << ans << endl;
	int res = max(1,ans-2*K);
	cout << N-res << endl;
	return 0;
}


Measured memory_bytes: 512
n = int(input())
s = input()
r = 0
g = 0
b = 0
rg = 0
gb = 0
br = 0
rgb = 0
for i in range(n):
    if s[i] == 'R':
        r+=1
        rg+=g
        br+=b
        rgb+=gb
    elif s[i] == 'G':
        g+=1
        rg+=r
        gb+=b
        rgb+=br
    else:
        b+=1
        br+=r
        gb+=g
        rgb+=rg

for i in range(n):
    for j in range(i+1, n):
        k = j+(j-i)
        if k>=n: break
        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            rgb-=1
print(rgb)




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

ll mod = 1000000007;

ll fact[200010];


ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;
  
    x = x % p;
  
    while (y > 0) 
    {
        if (y & 1) 
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p; 
    } 
    return res; 
}


ll modInverse(ll n, ll p) 
{ 
    return power(n, p-2, p); 
}

void init(){

    fact[0] = 1;

	for(int i=1;i<=200005; i++){
		fact[i] = (fact[i-1]*i)%mod;
	}
}

ll sol(ll r, ll d){
    ll ans = fact[r+d];
    ans = (ans*modInverse(fact[r],mod))%mod;
    ans = (ans*modInverse(fact[d],mod))%mod;
    
    return ans;
}

int main() {
    init();
    int h,w,a,b;
    cin>>h>>w>>a>>b;
    
    ll ans = 0;
    ll t;
    
    for(int i=0; i<h-a; i++){
        t = 1;
        t = (t*sol(i,b-1))%mod;
        t = (t*sol(w-b-1,h-i-1))%mod;
        // cout<<i<<":"<<b<<" "<<w-b-1<<":"<<h-i-1<<'\n';
        ans = (ans + t)%mod;
    }
    
    cout<<ans;
    
    return 0;
}







Measured memory_bytes: 1792
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
template <typename T> using posteriority_queue = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
// const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
template <typename T> void unique(vector<T> &a) { a.erase(unique(ALL(a)), a.end()); }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int n; cin >> n;
  vector<int> x(n), y(n); REP(i, n) cin >> x[i] >> y[i];
  function<double(double, double)> r = [&](double X, double Y) {
    double mx = 0;
    REP(i, n) chmax(mx, sqrt((x[i] - X) * (x[i] - X) + (y[i] - Y) * (y[i] - Y)));
    return mx;
  };
  function<double(double)> f = [&](double X) {
    double lb_y = 0, ub_y = 1000;
    REP(_, 100) {
      double mid1 = (lb_y + lb_y + ub_y) / 3, mid2 = (lb_y + ub_y + ub_y) / 3;
      if (r(X, mid1) < r(X, mid2)) {
        ub_y = mid2;
      } else {
        lb_y = mid1;
      }
    }
    return r(X, lb_y);
  };
  double lb_x = 0, ub_x = 1000;
  REP(_, 100) {
    double mid1 = (lb_x + lb_x + ub_x) / 3, mid2 = (lb_x + ub_x + ub_x) / 3;
    if (f(mid1) < f(mid2)) {
      ub_x = mid2;
    } else {
      lb_x = mid1;
    }
  }
  cout << f(lb_x) << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

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

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

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

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


int main(){
ll a,b,c,d;
cin>>a>>b>>c>>d;
cout<<min(a,b)+min(c,d)<<endl;
}









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

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll a,b,c,k;	cin>>a>>b>>c>>k;
	if(k%2){
		cout<<b-a;
	}
	else{
		cout<<a-b;
	}

	return 0;
}

Measured memory_bytes: 256
func readIntArray() -> [Int] {
    readLine()!.split(separator: " ").map({Int($0)!})
}

var line = readIntArray()
let (N, M, Q) = (line[0], line[1], line[2])

var queries: [[Int]] = (0..<Q).map({_ in readIntArray()})
var ans = 0

func dfs(_ A: [Int]) {
    if A.count == (N + 1) {
        ans = max(ans, score(A))
        return
    }
    
    var last = A.last!
    while last <= M {
        dfs(A + [last])
        last += 1
    }
}

func score(_ A: [Int]) -> Int {
    var score = 0
    (0..<Q).forEach({i in
        let query = queries[i]
        let (a, b, c, d) = (query[0], query[1], query[2], query[3])
        if (A[b] - A[a] == c) {
            score += d
        }
    })
    return score
}

dfs([1])
print(ans)


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

vector<vector<pair<int, int>>> g;
vector<vector<int>> gInv;
vector<int> onRoute;
vector<bool> chk;

void dfs(int p)
{
  if (chk[p])
    return;
  chk[p] = true;
  onRoute[p]++;
  for (auto& nxt : g[p])
    dfs(nxt.first);
}

void dfsInv(int p)
{
  if (chk[p] || onRoute[p] == 0)
    return;
  chk[p] = true;
  onRoute[p]++;
  for (auto& nxt : gInv[p])
    dfsInv(nxt);
}

int main()
{
  int n, m;
  cin >> n >> m;
  g.resize(n);
  gInv.resize(n);
  rep(i, m)
  {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    c = -c;
    g[a].emplace_back(b, c);
    gInv[b].push_back(a);
  }
  onRoute.resize(n);
  fill(onRoute.begin(), onRoute.end(), 0);
  chk.resize(n);
  fill(chk.begin(), chk.end(), false);
  dfs(0);
  fill(chk.begin(), chk.end(), false);
  dfsInv(n - 1);
  vector<ll> score(n, LONG_LONG_MAX);
  score[0] = 0;
  rep(i, n)
    rep(j, n)
    {
      if (onRoute[j] != 2 || score[j] == LONG_LONG_MAX)
        continue;
      for (auto& k : g[j])
      {
        if (onRoute[k.first] != 2)
          continue;
        if (score[k.first] > score[j] + k.second)
        {
          score[k.first] = score[j] + k.second;
          if (i == n - 1)
          {
            cout << "inf\n";
            return 0;
          }
        }
      }
    }
  cout << -score[n - 1] << endl;
  return 0;
}

Measured memory_bytes: 384
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>

#define lint long long
#define REP(i, x, n) for(int i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;

int main(){
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    string ans = t;
    rep(i, n){
        if(s == ans.substr(0, n)){
            break;
        }
        ans = s.substr(0, i+1) + t;
    }
    cout << ans.size() << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll> nex[20];
vector<ll> nv;

map<ll,int> memo;

const int INF = (1<<29);
ll solve(ll x){
  bool f = false;
  if( memo.count(x) != 0 ) return memo[x];
  int ret = 0;
  int sid = upper_bound(nv.begin(),nv.end(),x)-nv.begin();
  for(int i=min((int)nv.size()-1,sid);i>-1;i--){ 
    if( x == nv[i] ){
      f = true; continue;
    }
    if( x % nv[i] == 0 ){
      //  cout << x/nv[i] << " - "<<  nv[i] << endl;
      int l = solve(x/nv[i]);
      int r = solve(nv[i]);
      if( l == -1 || r== -1 ) continue;
      ret = max( l+r, ret );
    }
  }
  if( ret == 0 ){
    if( !f ) return memo[x] = -1;
    return memo[x] = 1;
  }
  return memo[x] = ret;
}


int main(){
  nex[0].push_back( 2LL );
  nex[0].push_back( 8LL );
  for(int k=0;k<18;k++){
    for(int i=0;i<(int)nex[k].size();i++){
      ll p = nex[k][i];
      nex[k+1].push_back( p*10LL + 2LL );
      nex[k+1].push_back( p*10LL + 8LL ); 
    }
  }
  for(int k=0;k<18;k++){
    for(int i=0;i<nex[k].size();i++){
      nv.push_back( nex[k][i] );
    }
  }
  sort(nv.begin(),nv.end());
  ll n;
  cin >> n;
  cout << solve(n) << endl;
  
}

Measured memory_bytes: 17100
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		long T = scan.nextLong();
		long[] t = new long[n];
		for (int i = 0; i < n; i++) {
			t[i] = scan.nextInt();
		}

		boolean f = true;
		long ans = 0;

		for (int i = 0; i < n-1; i++) {
			if(t[i+1]-t[i] < T) {
				ans+=t[i+1]-t[i];
			} else {
				ans+=T;
				f = false;
			}
		}

		ans += T;
		System.out.println(ans);
	}
}


Measured memory_bytes: 64680
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
for _ in range(k):
    c = [0] * n
    for i in range(n):
        c[max(0, i-a[i])] += 1
        if a[i] + i + 1 < n:
            c[a[i] + i + 1] -= 1
    j = 0
    for i in range(n):
        j += c[i]
        a[i] = j

    if sum(a) == n * n:
        print(*([n] * n))
        break
else:
    print(*a)


Measured memory_bytes: 152768
#include <bits/stdc++.h>
using namespace std;
#define fo(i,n) for(int i=0;i<n;i++)
int main(){
    int n,m;
    cin >>n >>m;
    fo(i,m){
        int temp;
        cin >>temp;
        n -= temp;
    }
    if(n>=0){
        cout<< n;
    }
    else{
        cout << -1;
    }
}

Measured memory_bytes: 3548
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#define INF 1000000007
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
signed main(){
    int n;
    cin>>n;
    int m;
    cin>>m;
    if((n+m)%2==0)cout<<(n+m)/2<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main() {
	string classname[9];
	int AMPM[9][2];
	for (int i = 0; i < 9; i++)
	{
		cin >> classname[i] >> AMPM[i][1] >> AMPM[i][2];
	}
	for (int i = 0; i < 9; i++)
	{
		cout << classname[i] << " " << AMPM[i][1] + AMPM[i][2] << " " << AMPM[i][1] * 200 + AMPM[i][2] * 300 << endl;
	}
	char a__;
	cin >> a__;
}

Measured memory_bytes: 2988
#include <iostream>
#include <bits/stdc++.h>
#define mod 100000000000000000
typedef long long ll;

using namespace std;

void Fastio(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

ll fact[1000006], inv[1000006];

ll fp(ll base, ll exp)
{
    if (exp == 0)
        return 1;
    ll ans = fp(base, exp / 2);
    ans = (ans * ans) % mod;
    if (exp % 2 != 0)
        ans = (ans * (base % mod)) % mod;
    return ans;
}

void calcFacAndInv(ll n)
{
    fact[0] = inv[0] = 1;
    for (ll i = 1; i <= n; i++)
    {
        fact[i] = (i * fact[i - 1]) ;
        inv[i] = fp(fact[i], mod - 2);
    }
}

ll ncr(ll n, ll r)
{
    return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod;
}

ll npr(ll n, ll r)
{
    return (fact[n] * inv[n - r]) % mod;
}

long double  NCR(int n, int m){
    long double res = 1;
    m = min(m, n - m);
    for(int i = 0; i < m; i++){
        res = res * ( n - i) / (i + 1);
 }
    return res;
}
ll tol(string a){
    ll res=0;
    for(int i=0; i<a.size(); i++){
        if(a[i]!='0'){swap(a[i],a[0]); break;}
    }
    for(int i=0; i<a.size(); i++){
        res*=10; res+=a[i]-'0';
    }
    return res;
}
int main()
{
    Fastio();
    ll n,m; cin>>n>>m;
    ll res=NCR(n,2)+NCR(m,2);
    if(m<2)res--;
    if(n<2)res--;
    cout<<res<<'\n';

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <map>
#include <algorithm>
#include <cmath>
#include <vector>
#include <fstream>
#include <string>
#include <random>
#include <queue>
#include <iomanip>
#include <functional>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <limits>
#include <functional>
#include <cassert>
#include <numeric>
#include <bitset>

#define FOR(x,n) for(int x = 0; x < n; x++)
#define PUT(x) cout << x << endl
#define DPUT(x) printf("%.15lf\n",x)
#define GET(x,y) std::get<x>(y)
#define CHMAX(x,y) x = std::max(x,y)
#define CHMIN(x,y) x = std::min(x,y)
#define SP_END (i != n - 1 ? ' ' : '\n') ;

using namespace std;

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vll = std::vector<ll>;
using vpll = std::vector<pll>;
using vpii = std::vector<pii>;
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using vvpii = std::vector<vpii>;
using vch = std::vector<char>;
using vvch = std::vector<vch>;
using tiii = std::tuple<int, int, int>;

const ll mod197 = 1000000007LL;
const ll INF = 10000000000LL;

const double PI11 = 3.14159265359;

const int dis[5] = { 0,1,0,-1,0 };

const int disD[4] = { 0,1,1,0 };

vpll graph[100010] = {};

ll memo[100010] = {};
bool visit[100010] = {};
ll h[100010] = {};

ll n, m;
ll loop = 0;

//行く先で既に値が決まっている場所があるか？
ll depth(ll i) {

	if (memo[i] != -1) {
		return memo[i];
	}

	loop++;

	if (loop > 200010) {
		return -1;
	}

	for (auto t : graph[i]) {
		ll res = depth(t.first);
		if (res != -1) {
			return res - t.second;
		}
	}
	return -1;

}
//その場所の値を矛盾無く割り当てられるか
bool solve(ll i,ll cost) {
	if (memo[i] == -1) {

		memo[i] = cost;

		for (auto t : graph[i]) {
			bool res = solve(t.first,cost + t.second);
			if (res == false) {
				return false;
			}
		}

		return true;
	}
	else if (memo[i] == cost) {
		return true;
	}
	else {
		return false;
	}
}

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

	for (int i = 0; i < m; i++) {
		int l, r, d;
		cin >> l >> r >> d;
		l--; r--;

		graph[l].push_back(pii(r, d));

		h[r]++;

	}

	fill(memo, memo + 100010, -1);

	for (int i = 0; i < n; i++) {
		if (h[i] == 0) {
			ll res = depth(i);
			if (res == -1) {
				res = 10000000LL * 100000LL + 10;
			}

			if (solve(i, res) == false) {
				cout << "No" << endl;
				return 0;
			}
		}
	}

	for (int i = 0; i < n; i++) {
		if (memo[i] == -1) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;

	return 0;
}


Measured memory_bytes: 11904
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ll long long
#define ld long double
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define INF 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846264338327950L
#define N 100005
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define vecl vector<ll>
#define umap unordered_map<ll,ll>
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define endl "\n"
using namespace std;
 
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};  
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
ll lcm(ll a, ll b) { return (a*b)/ gcd(a,b);}





void test_case() {

    
    

   int n , p;
   cin>>n>>p;

   string s;
   cin>>s;

   if( 10 % p == 0) {

       ll ans = 0;
       for(int i=n; i>=1; i--) {
           ll val = s[i-1] - '0';

           if(val % p == 0) {
               ans+= i;
           }
       }

       cout<<ans<<endl;
       return;
   }

   ll ans = 0;

   ll mul = 1;
   vecl L(p+1, 0);
   L[0] = 1;

   ll r = 0;

   for(int i=n-1; i>=0; i--) {
       r = ((s[i] - '0') * mul + r) % p;
       ans+= L[r];
       L[r]++;
       mul = (mul * 10) % p;
   }

   cout<<ans<<endl;




}
 
 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout<<fixed<<setprecision(20);
 
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
 
 
    int t = 1;
    // cin >> t;
    while (t--)
    {
        test_case();
    }
}


Measured memory_bytes: 3760
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
bool suf(ld a, ld b, ld c, ld d) {
	if (b <= c || d <= a) return 0;
	return 1;
}//[a,b),[c,d)
ll fact(ll i) {
	ll sum = 1;
	for (ll j = 2; j <= i; j++)
		sum = (sum* j) % Mod;
	return sum;
}//階乗(正）
#define int long long
const long long inf = 4523372036854775807;
const int iinf = 1500000000;
//---------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
int n, c[501], s[501], f[501];
signed main() {
	cin >> n;
	for (int i = 0; i < n-1; i++)
		cin >> c[i] >> s[i] >> f[i];
	for (int i = 0; i < n; i++) {
		int t = s[i];
		for (int j = i; j < n - 1; j++) {
			t = max(s[j], (int)ceil(t*1.0 / f[j])*f[j]) + c[j];
		}
		cout << t << endl;
	}
	getchar(); getchar();
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<string>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#define P pair<long long, long long>


using namespace std;
const long long int MOD=1e9+7;

int main(){
  int a, b;
  cin >> a >> b;
  for(int i=1;i<=100000;i++){
    if(i*108/100 - i==a && i*110/100 - i==b){
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

void solve(long long N, long long X, std::vector<long long> L){
    int count = 1;
    int tmp = 0;
    REP(i, N) {
        tmp += L[i];
        if (tmp <= X) count++;
    }
    cout << count << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long N;
    scanf("%lld",&N);
    long long X;
    scanf("%lld",&X);
    std::vector<long long> L(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&L[i]);
    }
    solve(N, X, std::move(L));
    return 0;
}


Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*
cout<<fixed<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=998244353;
const llint moe=992186091;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
	int n,t;cin>>n>>t;
	double ans=0;
	for(int i=0;i<n;i++){
		double x,h;cin>>x>>h;
		maxeq(ans,h*t/x);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3312
#include <iostream>

int main(int argc, char* argv[]){
  int A, B, C, D;  
  std::cin >> A;
  std::cin >> B;
  std::cin >> C;
  std::cin >> D;
  
  int tail;
  if(A > C){
    tail = A;
  }
  else{
    tail = C;
  }

  int head;
  if(B > D){
    head = D;
  }
  else{
    head = B;
  }

  if((head - tail) > 0){
    std::cout << (head - tail) << std::endl;
  }else{
    std::cout << 0 << std::endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int solve(){
    int n;
    cin >>n;
    vector<int> c(n);
    rep(i,n) cin >>c[i];

    int q;
    cin >>q;
    vector<int> t(q),x(q),d(q);
    rep(i,q){
        cin >>t[i] >>x[i] >>d[i];
        --x[i];
    }

    vector<int> a(n);
    rep(i,q){
        if(t[i]==1){
            a[x[i]] += d[i];
            if(a[x[i]] > c[x[i]]) return x[i]+1;
        }
        else{
            a[x[i]] -= d[i];
            if(a[x[i]] < 0) return x[i]+1;
        }
    }
    return 0;
}

int main(){
    cout << solve() << endl;
    return 0;
}



Measured memory_bytes: 3892
import sys

X, Y = map(int, input().split())
ans = 'No'
if X > 100 or Y > 100:
  print(ans)
  sys.exit()
if Y > X*4 or Y < X*2:
  print(ans)
  sys.exit()
if Y % 2 == 1:
  print(ans)
  sys.exit()

for a in range(X + 1):
  b = X - a
  if 2 * a + 4 * b == Y:
    ans = 'Yes'
    print(ans)

Measured memory_bytes: 9212
#include<iostream>
#include<cmath>


using sll = signed long long;

using ull = unsigned long long;

const auto large = 1000'000'007;
auto put(ull u_) {
	ull u = 1;
	for (size_t i{ 2 }; i <= u_; i++) {
		u *= i;
		u %= large;
	}
	return u;
}

int main() {
	//std::cout << put(3);
	
	
	ull N, M;
	std::cin >> N >> M;
	
	
	auto x = std::abs(sll(N - M));

	ull res = {x==0? put(N)*put(M)%large*2%large:
		x==1?((put(N)*put(M)%large)) %large : 0
	};

	std::cout << res << "\n";
	return 0;
}


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

int main(){
	ll n, k, a, b;
	cin >> n >> k;
	vector<pair<ll, ll>> vp;
	rep(i, n){
		cin >> a >> b;
		vp.push_back(make_pair(a, b));
	}
	sort(vp.begin(), vp.end());
	
	for(auto p : vp){
		k -= p.second;
		if(k <= 0){
			cout << p.first << endl;
			return 0;
		}
	}
	
	return 0;
}

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

#define         pb         push_back
#define         sf(x)      scanf("%d",&x)
#define         sfl(x)     scanf("%lld",&x)
#define         pf(x)      printf("%d\n",x)
#define         pfl(x)     printf("%lld\n",x)
#define         endl       '\n'
#define         pii        pair<int,int>
#define         mapii      map<int,int>
#define         mapll      map<ll,ll>
#define         mapci      map<char,int>
#define         mapcl      map<char,ll>
#define         mapsi      map<string,int>
#define         mapsl      map<string,ll>
#define         pll        pair<ll,ll>
#define         vi         vector<int>
#define         vl         vector<ll>
#define         vd         vector<double,double>
#define         all(c)     c.begin(),c.end()
#define         F          first
#define         S          second
#define         mp         make_pair
#define        ftc(x)      cerr << #x << ": " << x << " " << endl;
#define         PI         acos(-1)
#define         lcm(a,b)   ((a*b)/__gcd(a,b))
#define        optimize    ios_base::sync_with_stdio(false);cin.tie(NULL);
#define        sqr(a)       ((a)*(a))

int main()
{
    
ll i,j,k,l,m,n,q,p1,p2,q1,q2,x,ans,l1,l2,l3,l4,l5,l6,l7,l8;


string s;
cin >> n  ;

if(n >=30)cout<<"Yes"<<endl;
else cout<<"No"<<endl;

}


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

using namespace std;

int main() {
    int n, l;
    char s[1000][1000], tmp[1000];
    cin >> n >> l;
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }

    for (int i = 1; i < n; i++) {
        for (int j = 1; j < n; j++) {
            if (strcmp(s[j - 1], s[j]) > 0) {
                strcpy(tmp, s[j - 1]);
                strcpy(s[j - 1], s[j]);
                strcpy(s[j], tmp);
            }
        }
    }
    for (int i = 0; i < n; i++){
        cout << s[i];
    }
    cout << endl;


    return 0;
}

Measured memory_bytes: 384
def gcd(a, b):
    while(b):
        a, b = b, a % b
    return a
def lcm(a, b):
	return a * b // gcd (a, b)

n = int(input())
t = [int(input()) for i in range(n)]
ans = 1
for i in t:
    ans = lcm(ans, i)
print(ans)

Measured memory_bytes: 3060
const input = require("fs").readFileSync("/dev/stdin", "utf8")
let cin = input.split(/ |\n/), cid = 0
const next = () => cin[cid++]
const nexts = (n) => cin.slice(cid, cid+=n).map(i=>parseInt(i))

const N = next()
const lastN = N.slice(-1)

const hon = [2, 4, 5, 7, 9]
const pon = [0, 1, 6, 8]
const bon = [3]

if (hon.includes(parseInt(lastN))) console.log('hon')
if (pon.includes(parseInt(lastN))) console.log('pon')
if (bon.includes(parseInt(lastN))) console.log('bon')

return


Measured memory_bytes: 29620
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100//000000000
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P,P>
#define T tuple<int,int,int> 
using namespace std;
 
vector<vector<int> > s;
vector<int> c;

int score(vector<int> held){
    vector<int> ld(26,0);
    int ans=0;
    rep(i,held.size()){
        int t=held[i];
        ld[t]=i+1;
        ans+=s[i][t];
        rep(j,26){
            ans-=c[j]*(55+i+1-ld[j]);
        }
    }
    return ans;
}

int main(){
    int d; cin >> d;
    vector<int> cc(26);
    c=cc;
    rep(i,26) cin >> c[i];
    vector<vector<int> > ss(d);
    s=ss;
    rep(i,d)rep(j,26){
        int a; cin >> a;
        s[i].push_back(a);
    }
 
    //vector<int> ld(26,0);
    vector<vector<int> > ds(26);
    vector<int> days(0);

    rep(i,d){
        int now=-INF;
        int whatday;
        rep(j,26){
            vector<int> tmp=days;
            tmp.push_back(j);
            int sc=score(tmp);
            if(sc>now){
                whatday=j;
                now=sc;
            }
        }
        days.push_back(whatday);
    }
    rep(i,d) cout << days[i]+1 << endl;
return 0;
}

Measured memory_bytes: 3720
import scala.collection.mutable.ArrayBuffer
import scala.io.StdIn._

object Main extends App {
  val Array(_n, _k, l, r) = readLine.trim.split(' ').map(_.toLong)
  val n = _n.toInt
  val k = _k.toInt
  val coin = readLine.trim.split(' ').map(_.toLong)
  val prev = Array.fill(k + 1){ArrayBuffer[Long]()}
  for (p ← 0 until (1 << (n / 2))) {
    var sum = 0L
    var count = 0
    for (i ← 0 until n / 2) {
      if ((p & (1 << i)) != 0) {
        sum += coin(i)
        count += 1
      }
    }
    if (count < prev.length) prev(count).append(sum)
  }
  val post = Array.fill(k + 1){ArrayBuffer[Long]()}
  for (p ← 0 until (1 << (n - n / 2))) {
    var sum = 0L
    var count = 0
    for (i ← 0 until (n - n / 2)) {
      if ((p & (1 << i)) != 0){
        sum += coin(i + n / 2)
        count += 1
      }
    }
    if (count < post.length) post(count).append(sum)
  }
  prev.indices.foreach(i ⇒ prev(i) = prev(i).sorted)
  post.indices.foreach(i ⇒ post(i) = post(i).sorted)
  var sum = 0L
  for (i ← 0 to k) {
    for (p ← prev(i)) {
      sum += upperBound(post(k - i), r - p) - lowerBound(post(k - i), l - p)
    }
  }
  println(sum)
  def lowerBound(array: ArrayBuffer[Long], target: Long): Int = {
    var left = 0
    var right = array.length
    while (left < right) {
      val mid = (left + right) / 2
      if (array(mid) < target) left = mid + 1
      else right = mid
    }
    right
  }
  def upperBound(array: ArrayBuffer[Long], target: Long): Int = {
    var left = 0
    var right = array.length
    while (left < right) {
      val mid = (left + right) / 2
      if (array(mid) <= target) left = mid + 1
      else right = mid
    }
    right
  }
}


Measured memory_bytes: 276320