akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

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

 vector<long long> a(n, 0);
 for (int i = 0; i < n; i++) {
   cin >> a[i];
 }

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

 if (n == 2) {
   cout << a[1] << endl;
   return 0;
 }

 if (n == 3) {
   int e, f, g;
   e = gcd(a[0], a[1]);
   f = gcd(a[0], a[2]);
   g = gcd(a[1], a[2]);
   cout << max(max(e, f), g) << endl;
   return 0;
 }

 long long max_koyaku = -1;
 for (long long i = 2; i < (n - 1); i += 1) {
   if (max_koyaku < 0) {
     max_koyaku = gcd(a[i], a[i+1]);
   } else {
     max_koyaku = gcd(max_koyaku, a[i+1]);
   }
 }

 long long max_first, max_second;
 max_first = gcd(a[0], max_koyaku);
 max_second = gcd(a[1], max_koyaku);

 long long first_gcd = gcd(a[0], a[1]);
 long long diff_count = 0;
 for (int i = 2; i < n; i++) {
   long long ans = gcd(first_gcd, a[i]);
   if (ans != first_gcd) {
     diff_count += 1;
   }
   if (diff_count > 1) {
     break;
   }
 }

 if (diff_count == 1) {
   if (first_gcd > max_first && first_gcd > max_second) {
     cout << first_gcd << endl;
   } else {
     if (max_first > max_second) {
       cout << max_first << endl;
     } else {
       cout << max_second << endl;
     }
   }
 } else if (max_first > max_second) {
   cout << max_first << endl;
 } else {
   cout << max_second << endl;
 }

 return 0;
}

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

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;
}

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

    int n;
    cin >> n;

    ll sum = 0;
    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
        sum += a[i];
    }

    int q;
    cin >> q;

    vector<int> b(q);
    vector<int> c(q);
    rep(i,q) cin >> b[i] >> c[i];

    vector<int> cnt(100010, 0);
    rep(i, n) {
        ++cnt[a[i]];
    }

    ll ans = sum;
    rep(i, q) {
        if(cnt[b[i]] > 0) {
            ans -= (cnt[b[i]] * ll(b[i]));
            ans += (cnt[b[i]] * ll(c[i]));
            cnt[c[i]] += cnt[b[i]];
            cnt[b[i]] = 0;
        }
        printf("%lld\n", ans);
    }
    return 0;
}

Measured memory_bytes: 4780
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod (1000000007)
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)

void solve() 
{
    int n;cin>>n;
    ll a[n];REP(i,n)cin>>a[i];
    ll ans=0;
    REP(i,60){
        ll num=0;
        REP(j,n)if(a[j]>>i&1)num++;
        num=num*(n-num)%mod;
        REP(j,i)num=num*2%mod;
        ans+=num;
        ans%=mod;
    }
    cout<<ans<<endl;
}

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


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

int n,m,d;

int main(){
    scanf("%d%d%d",&n,&m,&d);
    double f=2.0*(n-d)/n/n;
    if(d==0)
        f/=2.0;
    printf("%.8lf",1.0*f*(m-1.0));
}


Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <memory.h>
 
 
 
using namespace std;
static const double EPS = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a,0,sizeof(a))
#define minus(a) memset(a,0xff,sizeof(a))
#define chmax(a,b) a=min((a),(b))
#define chmin(a,b) a=max((a),(b))
 
 
#define MOD 1000000007
 
typedef pair<int,int>P;
#define INF (1LL<<61)	//
 
struct edge { 
	int from, to;
	ll cost; 
	edge (int from_, int to_, ll cost_){
		from=from_; to=to_; cost=cost_;
	}
};
 
int V,E;
vector<edge> edges;
//vector<edges> G;

int v,e,r;
ll dist[1005];
int ans[1005];
bool neg[1005];


void go(int s){
	fill(dist,dist+v,-INF);
	dist[s]=0;
	bool flg;
	int from,to;
	rep(i,v){
		flg=false;
		rep(j,edges.size()){
			from=edges[j].from; to=edges[j].to;
			if(dist[from]!=INF && dist[to]<dist[from]+edges[j].cost){
				dist[to] = dist[from]+edges[j].cost;
				if(i==v-1 && to==v-1){
					cout<<"inf"<<endl;
					return;
				}
			}
		}
	}
	cout << dist[v-1] << endl;

}

int main() {

	cin>>v>>e;
	int s,t;
	ll d;
	rep(i,e){
		cin>>s>>t>>d;s--;t--;
		edges.push_back(edge(s,t,d));
	}
	go(0);
	return 0;
}




Measured memory_bytes: 384
n, m, c = map(int, input().split())
b = list(map(int, input().split()))

ans = 0
for i in range(n):
    a = list(map(int, input().split()))
    if sum([a[j] * b[j] for j in range(m)]) + c > 0:
        ans += 1

print(ans)


Measured memory_bytes: 2940
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
def do():
    a,b,c =STRM()
    print(a[0]+b[0]+c[0])
if __name__ == '__main__':
    do()

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100003,INF=1<<30;

int main(){
    
    string S;cin>>S;
    S+='R';
    int N=S.size();
    
    vector<int> A(N);
    
    bool flag=false;
    int cnt=1,start=0;
    int point=-1;
    for(int i=1;i<N;i++){
        if(S[i]=='L'&&S[i-1]=='R'){
            flag=true;
            point=i-1;
        }else if(flag&&S[i]=='R'){
            int end=i-1;
            if(start%2==point%2){
                A[point]+=(point-start)/2;
                A[point+1]+=(point-start)/2;
            }else{
                A[point]+=(point-start)/2;
                A[point+1]+=(point-start)/2+1;
            }
            if((point+1)%2==end%2){
                A[point]+=(end-point-1)/2;
                A[point+1]+=(end-point-1)/2;
            }else{
                A[point]+=(end-point-1)/2+1;
                A[point+1]+=(end-point-1)/2;
            }
            A[point]++;
            A[point+1]++;
            
            start=i;
            flag=false;
        }
    }
    
    for(int i=0;i<N-1;i++){
        if(i) cout<<" ";
        cout<<A[i];
    }
    
    cout<<endl;
}


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

ll query(int a,int b,int c,int d) {
  int l = max(a,c);
  int r = min(b,d);
  if(r-l < 0) return 0;
  else return r-l+1;
}

int main(){
  int n;
  cin >> n;
  int t[n], a[n];
  rep(i,n) cin >> t[i];
  rep(i,n) cin >> a[i];
  reverse(a,a+n);
  vector<int> lt(n,0), rt(n,0), la(n,0), ra(n,0);
  lt[0] = t[0]; rt[0] = t[0]; la[0] = a[0]; ra[0] = a[0];
  for(int i = 1; i < n; i++) {
    if(t[i] > t[i-1]) {
      lt[i] = t[i]; rt[i] = t[i];
    } else {
      lt[i] = 1; rt[i] = t[i];
    }
    if(a[i] > a[i-1]) {
      la[i] = a[i]; ra[i] = a[i];
    } else {
      la[i] = 1; ra[i] = a[i];
    }
  }
  reverse(la.begin(),la.end());
  reverse(ra.begin(),ra.end());
  ll ans = 1;
  rep(i,n) (ans *= query(lt[i],rt[i],la[i],ra[i])) %= mod;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2560
/////////// <----------------------  Quicksilver_ ---------------------> ///////////

#include <iostream>
#include <bits/stdc++.h>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <map>
#include <iterator>
#include <iomanip>
#include <queue>
#include <utility>
#include <set>
#include <cstring>

using namespace std;
#define ll long long int
#define endl "\n"
#define c(x) ll x;cin>>x
#define cc(x,y) ll x,y;cin>>x>>y
#define ccc(x,y,z) ll x,y,z; cin>>x>>y>>z
#define db long double
#define fast cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(false)
#define inf 200000000000000
#define mod 1000000007
#define eps 1e-7
#define PI 3.1415926535897932385
#define pb push_back
#define bitc  __builtin_popcountll
#define mp make_pair
#define ff first
#define ss second
#define all(ar) ar.begin(), ar.end()
#define len(x) (ll)(x).size()
#define fr(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = n - 1; i >= 0; i--)
#define frr(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)
#define foreach(it,ar) for (auto it = ar.begin(); it != ar.end(); it++)
#define fill(ar,val) memset(ar, val, sizeof(ar))
#define print(arr,n) rep(i,n) cout<<arr[i]<<" "; cout<<endl
#define print2(arr,n,m) rep(i,n){ rep(j,m) cout<<arr[i][j]<<" "; cout<<endl; }
#define dyn1(arr,n) ll* arr=new ll[n]; rep(i,n) arr[i]=0;
#define dyn2(arr,n,m) ll** arr=new ll*[(n)]; rep(i,n) arr[i]=new ll[m]; rep(i,n) rep(j,m) arr[i][j]=0
#define carr(arr,n) rep(i,n) cin>>arr[i]
#define carr2(arr,n,m) rep(i,n) rep(j,m) cin>>arr[i][j]
#define debug(a) cout<<" :: "<<#a<<" == "<<a<<endl
#define debug2(a,b) cout<<" :: "<<#a<<" == "<<a<<" :: "<<#b<<" == "<<b<<endl
typedef pair<ll,ll> pii;
typedef vector<pii> vpii;

inline ll maxim(ll a,ll b) {if(a>b) return a; else return b;}
inline ll minim(ll a,ll b) {if(a<b) return a; else return b;}
inline bool equals(double a, double b){ return fabs(a - b) < 1e-9; }
ll gcd(ll a, ll b){ return b==0 ? a : gcd(b, a%b); }


ll binpow(ll a, ll b)
{
    ll res = 1;
    while (b > 0)
    {
        if (b & 1) res = (res * a)%mod;
        a = (a * a)%mod;
        b >>= 1;
    }
    return res;
}


ll arr[1000010][2];
ll temp[1000010];
ll cost[1000010]={0};
ll mat[150][150]={0};

vector<ll> love;
map<pair<db,db> ,ll> centres;


int main()
{
  fast;
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  cout<<setprecision(10)<<fixed;
  c(n);
  ll total=(n*(n+1))/2;
  ll n_5=n/5;
  ll n_3=n/3;
  ll n_15=n/15;
  total-=((n_5)*(n_5+1)*(5))/2;
  total-=((n_3)*(n_3+1)*(3))/2;
  total+=((n_15)*(n_15+1)*(15))/2;
  cout<<total<<endl;

  return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<algorithm>
#include <cassert>
#include<string>
#include<vector>
#include <utility>
#include <math.h>
#include<cmath>
# include <set>
# include <iomanip>
# include <functional>
# include <queue>
#include<map>
#define INF 1000000009;
using namespace std;
int gcd(int a, int b) {
	while (a % b != 0) {
		int c = 0;
		c = a % b;
		a = b;
		b = c;
	}
	return  b;
}


int main() {
	
	int naga, mizi,ans=1;
	cin >> naga>>mizi;
	for (int i = 0; i < naga; i++) {
		if (i == 0) {
			ans = ans * mizi;
		}
		else { ans = ans * (mizi - 1); }
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<map>
#include<bits/stdc++.h>
#include<string>
#include<algorithm>
typedef long long int ll;
using namespace std;
#define MAX   150002
#define X first
#define Y second
#define MOD 1000000007
#define fr(a,b,c) for(ll a=b;a<c;++a)
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

ll t,n,i,j;
int main()
{
    fastio;
    cin>>n;
    double x;
    double sum=0.0;
    fr(i,0,n)
    {
        cin>>x;
        x=1/x;
        sum=x+sum;
    }
    cout<<setprecision(15)<<(1/sum)<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){

     int N, j, max, sum=0;
     int p[10000];

    scanf("%d", &N);

     for(j = 0; j < N; ++j){
          scanf("%d", &p[j]);
     }
   
     max = p[0];

     for(j = 1; j < N; ++j){
         if(max < p[j]){
            max = p[j];
         }
     }

     for(j = 0; j < N; ++j){
          sum += p[j];
     }

     printf("%d\n", sum - max / 2);

     return 0;
}

     


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

int main(){
    int n;
    cin >> n;
    set<string> ans;
    rep(i,n){
        string s;
        cin >> s;
        ans.insert(s);
    }
    cout << ans.size() << endl;
    return 0;
}

Measured memory_bytes: 19156
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <climits>
#include <utility>
typedef long long ll;
using namespace std;

int main(void){
  char c;
  cin>>c;

  printf("%c\n",c+1);
  
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  
  int state = 0;
  int ans = 1;
  for (int i = 1; i < n; ++i) {
    if (state == 0) {
      if (a[i] - a[i-1] > 0) state = 1;
      else if (a[i] - a[i-1] < 0) state = -1;
    } else if (state == 1) {
      if (a[i] - a[i-1] < 0) {
        ++ans;
        state = 0;
      }
    } else {
      if (a[i] - a[i-1] > 0) {
        ++ans;
        state = 0;
      }
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3768
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int s = sc.nextInt();
        int count = 1;
        while (true) {
            if (s == 4 || s == 2 || s == 1)
                break;
            if (s % 2 == 0) {
                s /= 2;
                count++;
            } else {
                s = s * 3 + 1;
                count++;
            }
        }
        System.out.println(count + 3);
    }
}

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

int main(){
    int n; cin >> n;
    string s; cin >> s;
    vector<int> b;
    int a = 0;
    rep(i,n){
        int ans = 0;
        rep(j,s.size()){
            if(s[j] == 'I') ans++;
            if(s[j] == 'D') ans--;
            a = max(a,ans);
        }
        b.pb(ans);
    }
    cout << a << endl;
    return 0;
} 

Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pii;
typedef pair<pii, ll>pi3;
ll mod = 1000000007;
ll gcd(ll a, ll b)
{
	for (;;)
	{
		if (a < b)swap(a, b);
		a %= b;
		if (a == 0)return b;
	}
}
int a[202020];
int main()
{
	ll s, t;
	scanf("%lld%lld", &s, &t);
	printf("%lld\n", min((s + s + t) / 4, t / 2));
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ST first
#define ND second
#define ll long long
#define ld long double
using namespace std;
using namespace __gnu_pbds;

// replace int with pair if multiset needed
typedef tree<int, null_type, greater<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ordered_set secik;

const int INF = 1e9 + 9;
const int MOD = 1e9 + 7;
const long long LINF = (ll)1e18 + 3;

// secik.insert({x, t++});
// secik.erase(secik.lower_bound({x,-1}));
// *secik.find_by_order(x)).first << "\n";
// secik.order_of_key(x)

//random_device device;
//mt19937 gener(device());
//uniform_int_distribution<int> gen(0,n-1);
//gen(gener); // generate random number

const int MAX = 1 << 20;

ll tr[2*MAX];

void update(int x, ll v){
	x += MAX;
	tr[x] = v;
	while(x /= 2){
		tr[x] = max(tr[2*x],tr[2*x+1]);
	}
}

ll query(int x, int y){
	ll res = 0;
	for(x += MAX, y += MAX; x < y; x >>= 1, y >>= 1){
		if(x&1) res = max(res,tr[x++]);
		if(y&1) res = max(res,tr[--y]);
	}
	return res;
}

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

	int n; cin >> n;
	vector<ll> h(n),a(n);
	
	for(int i = 0; i < n; i++) cin >> h[i];
	for(int i = 0; i < n; i++) cin >> a[i];

	vector<ll> dp(n);
	
	for(int i = 0; i < n; i++){
		dp[i] = a[i] + query(0,h[i]);
		update(h[i],dp[i]);
	}

	ll res = 0;
	for(int i = 0; i < n; i++) res = max(res,dp[i]);
	
	cout << res;


}

Measured memory_bytes: 11520
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
int d[12][12];
int main()
{
	int h,w,out=0,a;
	cin>>h>>w;
	rep(i,10) rep(j,10) cin>>d[i][j];rep(k,10) rep(i,10) rep(j,10) d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
	rep(i,h) rep(j,w){
		cin>>a;if(a>=0) out+=d[a][1];
	}
	cout<<out<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll h,w,n;
ll len(ll x,ll y){
  if(x==0)
    return y;
  if(y==h)
    return h+x;
  if(x==w)
    return h+w+(h-y);
  if(y==0)
    return h+w+h+(w-x);
  return -1;
}

vector<P> pos;
map<ll,int> zahyou;
vector<ll> X;
int tbl[300001];
int main(){
  cin >> h >> w >> n;
  for(int i=0;i<n;++i){
    ll x1,y1,x2,y2;
    cin >> y1 >> x1 >> y2 >> x2;
    ll left = len(x1,y1);
    ll right = len(x2,y2);
    if(right < left)
      swap(right,left);
    if(left>=0)
      pos.push_back(P(left,right));
  }
  sort(pos.begin(), pos.end());

  for(P p:pos){
    X.push_back(p.first);
    X.push_back(p.second);
  }
  sort(X.begin(), X.end());
  for(int i=0;i<X.size();++i){
    zahyou[X[i]]=i;
  }
  for(P p:pos){
    tbl[zahyou[p.first]]++;
    tbl[zahyou[p.second]+1]--;
  }
  for(int i=1;i<=300000;++i){
    tbl[i]+=tbl[i-1];
  }

  bool ok = true;
  for(P p:pos){
    if(tbl[zahyou[p.first]]!=tbl[zahyou[p.second]])
      ok=false;
  }

  if(ok)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
 
  return 0;
}


Measured memory_bytes: 17520
#include<iostream>
using namespace std;
int main (){
    
    int m,f,r;
    
    while (1) {
        
        cin >> m >> f >> r;
        
        if ((m == -1) && (f == -1) && (r == -1)) break;
        
        if ((m == -1) || (f == -1)) {
            
            cout << 'F' << endl;
            
        } else if (m + f >= 80) {
            
            cout << 'A' << endl;
            
        } else if (m + f >= 65) {
            
            cout << 'B' << endl;
            
        } else if (m + f >= 50) {
            
            cout << 'C' << endl;
            
        } else if (m + f >= 30) {
            
            if (r >= 50) {
                
                cout << 'C' << endl;
                
            } else {
                
                cout << 'D' << endl;
                
            }
            
        } else {
            
            cout << 'F' << endl;
            
        }
        
    }
    
    return 0;
    
}


Measured memory_bytes: 3080
/* "It's okay if you hate me. I hate me too." */

#include <bits/stdc++.h>

using namespace std;

char s[3][12];

int main() {
	for (int i = 0; i < 3; ++i)
		scanf(" %s", s[i]);
	for (int i = 0; i < 3; ++i)
		printf("%c", s[i][0]-'a'+'A');
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<iostream>

using namespace std;

struct Node{
  int key;
  Node *right, *left, *parent;
};

Node *root, *NIL;

Node * find(Node *u, int k){
  while ( u != NIL && k != u->key ) {
    if ( k < u->key ) {
      u = u->left;
    } else
      u = u->right; 
    }
  return u;
}

void insert(int k) {
  Node *x = root;
  Node *y = NIL;
  Node *z;

  z = (Node *)malloc(sizeof(Node));
  z->key = k;
  z->right = NIL;
  z->left = NIL;

  while ( x != NIL ) {
    y = x;
    if ( z->key < x->key ) {
      x = x->left;
    } else {
      x = x->right;
    }
  }
  z->parent = y;
  
  if ( y == NIL ) {
    root = z;
  } else {
    if ( z->key < y->key ) {
      y->left = z;
    } else {
      y->right = z;
    }
  } 
}

void inorder(Node *u){
  if ( u == NIL ) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}

void preorder(Node *u) {
  if ( u == NIL ) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}

int main() {
  int n, i, x;
  string com;
  
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ) {
    cin >> com;
    if ( com[0] == 'f' ) {
      scanf("%d", &x );
      Node *t = find(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com == "insert" ) {
      scanf("%d", &x);
      insert(x);
    } else if ( com == "print") {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}


Measured memory_bytes: 22084
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define repr(i,a,b) for (int i = a; i > b; --i)
#define mm(lamb, tttt) memset(lamb, tttt, sizeof lamb)
 
#define null NULL
#define eps 0.000000001
#define mod 1000000007
#define PI 3.14159265358979323846
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define sz(V) (int)V.size()
#define _ <<" "<<
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair <int, int> ii;
typedef pair<int, pair<int,int> > iii;
typedef vector<ii> vii;
vector<int >v[200000];
ll dp[200000][2];
bool visited[200000];
ll dfs(int x)
{
	//cout<<x<<endl;
	visited[x] = 1;
	ll b = 1;
	ll w = 1;
	if(v[x].size() == 1 && visited[v[x][0]] == 1)
	{
		//cout<<x<<"hfoi"<<endl;
		dp[x][0] = 1;
		dp[x][1] = 1;
		return 2;
	}

	for(int i=0;i<v[x].size();i++)
	{
		
		if(visited[ v[x][i] ] == 0)
		{
			dfs(v[x][i]);
			//cout<<v[x][i] _ dp[v[x][i]][1] _ dp[v[x][i]][0]<<endl;
			b = (b* dp[ v[x][i] ][1]) % mod;
			w = (w*((dp[v[x][i]][1] + dp[v[x][i]][0])%mod) )%mod;
		}
		

		
	}

	dp[x][0] = b;
	dp[x][1] = w;
	return (b+w)%mod;

}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 	
	//freopen ("test.txt","r",stdin);
	int n;cin>>n;
	if(n==1)
	{
		cout<<2;return 0;
	}
	for (int i = 0; i < n; ++i)
	{
		int x,y;
		cin>>x>>y;
		v[x].pb(y);
		v[y].pb(x);
	}


	cout<<dfs(1);
}

Measured memory_bytes: 17920
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

int main(){
    int N;
    cin >> N;
    int a[N];
    for(int i = 0;i < N;i++){
        cin >> a[i];
    }
    sort(a,a + N);
    for(int i = 0;i < N-1;i++){
        if(a[i] == a[i + 1]){
            cout << "NO" << endl;
            return 0;
        }else{
            continue;
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
using namespace std;

int main() {
  for(int tci = 0; ; tci++) {
    int MW; scanf("%d", &MW); if(MW==0) break;
    int N; scanf("%d", &N);
    static int V[10000], W[10000];
    for(int i = 0; i < N; i++) {
      scanf("%d,%d", V+i, W+i);
    }
    int dp[1001];
    for(int w = 0; w <= MW; w++) dp[w] = 0;
    for(int i = 0; i < N; i++) {
      for(int w = MW; w >= W[i]; w--) {
        dp[w] = max(dp[w], dp[w-W[i]]+V[i]);
      }
    }
    pair<int,int> res(0,0);
    for(int w = 0; w <= MW; w++) {
      res = max(res, make_pair(dp[w],-w));
    }
    printf("Case %d:\n%d\n%d\n", tci+1, res.first, -res.second);
    // fprintf(stderr, "dp = {");
    // for(int w = 0; w <= MW; w++) {
    //   fprintf(stderr, "%d, ", dp[w]);
    // }
    // fprintf(stderr, "}\n");
  }
  return 0;
}

Measured memory_bytes: 1044
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <limits.h>
#include <cmath>
#include <queue>
#include <map>
#include <iomanip>
#include <random>
#include <fstream>
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.14159265358979323846
using namespace std;
using ll = long long;

ll gcd(ll a, ll b)
{
  ll r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}

int main()
{

  cout << fixed << setprecision(10);

  int n; cin >> n;
  vector<int> x(n),y(n);
  rep(i,n){cin>>x[i]>>y[i];}
  double sum=0;

  rep(i,n){
    for(int j=i+1; j<n; j++){
      sum+=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
    }
  }

  cout << sum*2/n << endl;


  return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

void J(char *str, int length){//???????????????
	int i;
	for(i=length;i>0;i--){
		str[i]=str[i-1];
	}
	str[0]=str[length];
	str[length]=0;
	return;
}
void C(char *str, int length){//???????????????
	int i;
	str[length]=str[0];
	for(i=0;i<length;i++){
		str[i]=str[i+1];
	}
	str[length]=0;
	return;
}
void E(char *str, int length){
	int i;
	char temp[length/2];
	for(i=0;i<length/2;i++){
		temp[i]=str[i];
	}
	for(i=0;i<length/2;i++){
		str[i]=str[(length/2)+(length%2)+i];
	}
	for(i=0;i<length/2;i++){
		str[(length/2)+(length%2)+i]=temp[i];
	}
}
void A(char *str, int length){
	int i;
	char temp[length];
	for(i=0;i<length;i++){
		temp[i]=str[length-1-i];
	}
	for(i=0;i<length;i++){
		str[i]=temp[i];
	}
}
void P(char *str, int length){
	int i;
	for(i=0;i<length;i++){
		if(str[i]=='0'){
			str[i]='9';
		}else if('1'<=str[i]&&str[i]<='9'){
			str[i]--;
		}
	}
}
void M(char *str, int length){
	int i;
	for(i=0;i<length;i++){
		if(str[i]=='9'){
			str[i]='0';
		}else if('0'<=str[i]&&str[i]<='8'){
			str[i]++;
		}
	}
}

void solve(){
	int i,length;
	char str[26];
	char route[7];

	scanf("%s",route);
	scanf("%s",str);

	for(i=0;str[i];i++);
	length=i;
	for(i=0;route[i];i++);
	for(i--;i>=0;i--){
		switch(route[i]){
			case 'J':
				J(str,length);
				break;
			case 'C':
				C(str,length);
				break;
			case 'E':
				E(str,length);
				break;
			case 'A':
				A(str,length);
				break;
			case 'P':
				P(str,length);
				break;
			case 'M':
				M(str,length);
				break;
		}
	}
	printf("%s\n",str);
}

int main(void){
	int n;
	scanf("%d",&n);
	for(;n;n--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 584
#include<bits/stdc++.h>
using namespace std;
vector<int>adj[1000001];
int vis[1000001];
void dfs(int src,int &node)
{
    node++;
    vis[src]=1;
    for(int child:adj[src])
    {   
       
        if(vis[child]==0)
        {
            dfs(child,node);
        }
    }
}
int main()
{
    int n,m,count,ans=-1;
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        int a,b;
        cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    for(int i=1;i<=n;i++)
    {
        if(vis[i]==0)
        {
            int count=0;
            dfs(i,count);
            //cout<<count<<" ";
            ans=max(ans,count);
        }
    }
    cout<<ans<<"\n";
    
    return 0;
}

Measured memory_bytes: 43452
package main

import (
	"fmt"
)

func main() {
	var n, k int

	fmt.Scan(&n, &k)

	a := make([]int64, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	// sum := make([]uint64, n+1)
	// for i := 0; i <n ; i++ {
	// 	if i == 0 {
	// 		sum[i] = 1
	// 	}
	// 	if i >= k {
	// 		sum[i+1] = a[i] * sum[i] / a[i+1 - (n -k)]
	// 		continue
	// 	}
	//
	// 	sum[i+1] = a[i] * sum[i]
	// }


	for i := k; i < n;i++ {
		pre :=  a[i-k]
		if a[i] > pre{
			fmt.Println("Yes")
			continue
		}

		fmt.Println("No")

		// if i == k {
		// 	continue
		// }

		// if sum[i] > sum[i-1] {
		// 	fmt.Println("Yes")
		// 	continue
		// }
		// fmt.Println("No")
	}
}


Measured memory_bytes: 6488
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};

#[fastout]
fn main() {
    input! {//
        h:usize,w:usize,
        s:[Chars;h],
    }

    let mut yoko = vec![vec![0; w]; h];
    let mut tate = vec![vec![0; w]; h];

    for i in 0..h {
        for j in 0..w {
            if s[i][j] == '.' {
                if j == 0 {
                    yoko[i][j] = 1;
                } else {
                    yoko[i][j] += yoko[i][j - 1] + 1;
                }
            }
        }
        for j in (0..w).rev() {
            if j == w - 1 {
                continue;
            } else {
                if yoko[i][j] != 0 {
                    yoko[i][j] = max(yoko[i][j], yoko[i][j + 1]);
                }
            }
        }
    }
    for j in 0..w {
        for i in 0..h {
            if s[i][j] == '.' {
                if i == 0 {
                    tate[i][j] = 1;
                } else {
                    tate[i][j] += tate[i - 1][j] + 1;
                }
            }
        }
        for i in (0..h).rev() {
            if i == h - 1 {
                continue;
            } else {
                if tate[i][j] != 0 {
                    tate[i][j] = max(tate[i][j], tate[i + 1][j]);
                }
            }
        }
    }
    let mut ans = 0;
    for i in 0..h {
        for j in 0..w {
            ans = max(ans, tate[i][j] + yoko[i][j] - 1);
        }
    }
    println!("{}", ans);
}


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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int64_t n; cin>>n;
  int64_t a=sqrt(n);
  while(true){
    if(n%a==0) break;
    a--;
  }
  cout<<a-1+n/a-1<<endl;  
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    ll n, m; cin>>n>>m;
    priority_queue<P> que;
    for(int i=0; i<n; i++){
        ll a; cin>>a;
        que.push(P(a, 1LL));
    }

    for(int i=0; i<m; i++){
        ll b, c; cin>>b>>c;
        que.push(P(c, b));
    }

    ll ans = 0;
    while(que.size()){
        ll num, cnt;
        tie(num, cnt) = que.top();
        que.pop();

        if(n - cnt >= 0){
            ans += num * cnt;
        }
        else{
            ans += num * max(n, 0LL);
        }

        n -= cnt;
    }

    cout << ans << endl;
}


Measured memory_bytes: 6384
#include <bits/stdc++.h>
using namespace std;
int main(){
    int K,i,p = 7;
    bool b = true;
    cin >> K;
    for(i = 0;i < K;i++){
        if(p % K == 0){
            b = false;
            cout << i + 1 << endl;
            break;
        }
        p = (p * 10 + 7) % K;
    }
    if(b){
        cout << -1 << endl;
    }
}

Measured memory_bytes: 3572
#include <iostream>
using namespace std;
const int N_MAX = 10000000;
bool isNotPrime[N_MAX + 1];
int main () {
	for (int i = 2; i * i < N_MAX; ++i) {
		if (!isNotPrime[i]) {
			for (int j = i << 1; j < N_MAX; j += i) {
				isNotPrime[j] = true;
			}
		}
	}
	int n;
	while (cin >> n, n) {
		for (; n > 13; n--) {
			if (!(isNotPrime[n] || isNotPrime[n - 2] || isNotPrime[n - 6] || isNotPrime[n - 8])) break;
		}
		cout << n << endl;
	}
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, pair<ll, ll> > P3;

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_N = int(2e5) + 5;
const int MAX_A = int(15e6);
const double EPS = 1e-8;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
string dir = "RDLU";
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()


int main() {
    ll n, ans;
    vector<ll> primes;
    cin >> n;
    ans = n;
    for(ll i = 2; i*i <= n; ++i){
        if(n%i==0)primes.push_back(i);
        while(n%i==0)n /= i;
    }
    if(n != 1)primes.push_back(n);
    for(auto p:primes){
        ans *= p-1;
        ans /= p;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3216
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll gcd(int a,int b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(int a,int b){return a*b/gcd(a,b);}
const int INF=1e9;
const ll INFS=1e18;
const int MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);

int main() {
  int n,k;
  cin>>n>>k;
  vector<int> a(n);
  rep(i,n) cin>>a[i];
  int ans=0;
  int cnt=1;
  while(cnt<n){
    ans++;
    cnt+=k-1;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3784
n, x = gets.chomp.split(" ").map(&:to_i);
a = gets.chomp.split(" ").map(&:to_i);

count = 0
(a.size-1).times do |i|
  tmp = x
  if a[i] + a[i+1] <= x
    next
  end

  count += (a[i] + a[i+1]) - x
  if (a[i] + a[i+1]) - x <= a[i+1]
    a[i+1] -= (a[i] + a[i+1]) - x
  else
        a[i+1] = 0
        a[i] -= x -  a[i+1]
  end
end
puts count


Measured memory_bytes: 9612
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1e9;
const long long INFL = 1LL<<60;

vector<ll> enum_divisor(ll m) {
  vector<ll> divisors;
  for (ll i = 1; i*i <= m; ++i) {
    if (m % i != 0) continue;
    divisors.push_back(i);
    if (i * i != m) divisors.push_back(m / i);
  }
  return divisors;
}

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

  ll n; cin >> n;
  vector<ll> d = enum_divisor(n);

  ll ans = INFL;
  for (ll e : d) {
    chmin(ans, e - 1 + (n/e) - 1);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int T = sc.nextInt();
		int[] t = new int[N];
		for(int i = 0; i < N; i++) {
			t[i] = sc.nextInt();
		}
		int ans = T;
		for(int i = 1; i < N; i++) {
			if(t[i]-t[i-1] < T) {
				ans += T - (T - (t[i] - t[i-1]));
			}else {
				ans += T;
			}
		}
		System.out.println(ans);
		sc.close();
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

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

using namespace std;

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

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

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

  int n;
  cin >> n;

  vector<string> s(n+5);
  map<string, int> cnt;
  rep(i, n) {
    cin >> s[i];
    sort(all(s[i]));
    cnt[s[i]]++;
  }

  i64 ans = 0;
  map<string, bool> exist;
  rep(i, n) {
    if (exist[s[i]]) continue;
    if (cnt[s[i]] == 0) continue;

    i64 K = cnt[s[i]] - 1;
    i64 tmp = K * (1 + K) / 2;
    ans += tmp;

    exist[s[i]] = true;
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 27648
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int mod = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);

int d[210][210];

int main()
{
    int n,m,R;
    cin >> n >> m >> R;
    vector<int> r(R);
    for(int i = 0; i < R; i++) cin >> r[i];
    for(int i = 0; i < 210; i++) for(int j = 0; j < 210; j++) d[i][j] = INF;
    for(int i = 0; i < m; i++){
        int a,b,c;
        cin >> a >> b >> c;
        d[a][b] = d[b][a] = c;
    }

    for(int k = 1; k <= n; k++){
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= n; j++){
                d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }

    int res = INF;
    sort(r.begin(),r.end());
    do{
        int sub = 0;
        for(int i = 1; i < r.size(); i++){
            sub += d[r[i-1]][r[i]];
        }
        res = min(res,sub);
    }while(next_permutation(r.begin(),r.end()));

    cout << res << endl;
        

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

ll countOnes(ll n){ 
	ll count = 1; 
	ll rem = 1; 
	while (rem != 0) { 
		rem = (rem * 10 + 1) % n; 
		count++;
    if(count >= 1e7){
      return -1;
    }
	} 
	return count; 
} 

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N; cin >> N;
  if(N%2 == 0){
    cout << -1 << endl;
    return 0;
  }
  if(N%7 == 0) N /= 7;
  if(N == 1){
    cout << 1 << endl;
    return 0;
  }
	cout << countOnes(N) << endl; 
}

Measured memory_bytes: 3648
n,m=map(int,input().split())
H=list(map(int,input().split()))
M=[1]*n
for i in range(m):
  a,b=map(int,input().split())
  if a==b:
    continue
  a-=1
  b-=1
  if H[a]>H[b]:
    M[b]=0
  elif H[a]<H[b]:
    M[a]=0
  else:
    M[a]=0
    M[b]=0
#print(M)
print(sum(M))

#memo:解説の解法と見比べる


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

using namespace std;

typedef long long ll;
typedef long double ld;
#define rep(i , j , n) for(long long i = j ; i <= n ; i++)
#define per(i , j , n) for(long long i = j ; i >= n ; i--)

const ll N = 123456;
const ll mod = 998244353;
const ld eps = 1e-5;

ll a[N];
ll dp[N];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cout.precision(10);

    int n , k;
    cin >> n >> k;

    rep(i , 1 , n) cin >> a[i];

    dp[1] = 0;

    rep(i , 2 , n) {
        dp[i] = INT_MAX;

        rep(j , max(i - k , 1LL) , i - 1) {
            dp[i] = min(dp[i] , dp[j] + abs(a[j] - a[i]));
        }
    }


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


Measured memory_bytes: 1792
R, G, B, N = map(int, input().split(" "))

ans=0

for count_r in range(N // R + 1):
    currnt_N = N - R * count_r
    for count_g in range(currnt_N // G + 1):
        #pass
        currnt_N = N - R * count_r - G * count_g
        if currnt_N % B == 0:
            ans += 1
            
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(ll (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(ll (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
const ll MOD=1e9+7;
using namespace std;

int main(){
 ll N,Q;
 cin >> N >> Q;
 string s;
 cin >> s;
 vector<int> n(s.size(), 0);
 n[0]=0;
 if(s[0]=='A' && s[1]=='C'){
   n[1]=1;
 }else{
   n[1]=0;
 }
 for(ll i=1;i<s.size();i++){
   if(s[i]=='A' && s[i+1]=='C'){
     n[i+1] = n[i-1]+1;
   }else{
     n[i+1] = n[i];
   }
 }

 vector<ll> l(Q),r(Q);
 rep(i,Q){
   cin >> l[i] >> r[i];
 }

 for(ll i=0;i<Q;i++){
   ll count=n[r[i]-1]-n[l[i]-1];
   cout << count << endl;
 }
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
template<C T>void pr(T a){cout<<a;ln;}
template<C T,C T2>void pr(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n,m,T=1;
  while(cin >> n >> m && n) {
    int d[m+1];
    mem(d);
    d[0]=n;
    int t=0;
    while(!d[m]) {
      int sum=0;
      rrep(i,m) {
        int x=d[i]/2;
        d[i+1]+=x;
        d[i]-=x*2;
        sum+=x;
      }
      d[0]+=sum;
      t++;
    }
    cout << "Case " << T++ << ": " << t << endl;
  }
}

int main() {
  ios::sync_with_stdio(0);cin.tie(0);
  Main();return 0;
}


Measured memory_bytes: 1204
#include<iostream>
#include<algorithm>
#include <string>
using namespace std;
int main() {
	int a, b, c, d, n = 0, ans = 0, ans2 = 0;
	string s;
	cin >>s;
	s.pop_back();
	s.pop_back();
	s.pop_back();
	s.pop_back();
	s.pop_back();
	s.pop_back();
	s.pop_back();
	s.pop_back();
	cout << s << endl;
}

Measured memory_bytes: 256
N , K , Q = map(int,input().split())
A = [int(input()) for _ in range(Q)]
score = [K-Q] * N
for i in range(Q):
  score[A[i] - 1] += 1

for i in range(N):
  if score[i]>0:
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 10448
while True:
    max,sum=map(int,input().split())
    if max==0 and sum==0:
        break
    cnt=0
    for i in range(1,max+1):
        for j in range(i+1,max+1):
            for k in range(j+1,max+1):
                if i+j+k==sum:
                    cnt+=1
    print(cnt)

Measured memory_bytes: 7680
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const int INF = (1<<30);
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; }

int main() {
    int N;
    cin >> N;
    int h[N];
    rep(i, N) cin >> h[i];
    int dp[100100];
    rep(i, 100100) dp[i] = INF;
    dp[0] = 0;
    dp[1] = abs(h[0]-h[1]);
    rep(i, N){
        chmin(dp[i+1], dp[i] + abs(h[i]-h[i+1]));
        chmin(dp[i+2], dp[i] + abs(h[i]-h[i+2]));
    }
    cout << dp[N-1] << endl;
    return 0;
}

Measured memory_bytes: 1024
/*
    ##############################
    #  Author: Pratyush Gaurav   #
    #  College: NIT ROURKELA     #
    ##############################
*/
#include <bits/stdc++.h>

using namespace std;

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

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

#define endl '\n'

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

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

bool compare(plli a, plli b) {
    double x = ((double)a.second) / a.first;
    double y = ((double)b.second) / b.first;
    return x > y;
}

void solve() {
    lli n, m;
    cin >> n >> m;
    vplli v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i].first >> v[i].second;
    }
    sort(all(v));

    lli cur = 0, ans = 0;

    for (int i = 0; i < n; ++i) {
        lli available = min(v[i].second, m - cur);
        ans += available * v[i].first;
        cur += available;
    }

    cout << ans << endl;
}

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



Measured memory_bytes: 1792
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define cy cout << "Yes" << endl
#define cn cout << "No" << endl
typedef long long ll;

void Main()
{
	int N;
    cin >> N;
  	if(N%2 == 0){ cout << N/2-1 << endl;}
	else { cout << (N-1)/2 << endl; }
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 11;
int n, arr[maxn];

int main() {
    cin>>n;
    int sum = 0;
    for(int i=0;i<n;i++) {
        cin>>arr[i];
        sum += arr[i];
    }

    for(int i=0;i<n;i++) {
        if(arr[i] >= sum - arr[i]) {
            cout<<"No\n";
            return 0;
        }
    }
    cout<<"Yes\n";
    return 0;
}

Measured memory_bytes: 256
<?php
    while (true) {
        $num = trim(fgets(STDIN));
        if (strlen($num <= 3)){
                break;
        }
        $hit = 0;
        $brow = 0;
        $num = str_split($num);
        for($i = 0; $i < 4; $i++){
            if($num[$i] == $num[5]){
                $brow++;
            }elseif($num[$i] == $num[6]){
                $brow++;
            }elseif($num[$i] == $num[7]){
                $brow++;
            }elseif($num[$i] == $num[8]){
                $brow++;
            }
        }
        if ($num[0] == $num[5]) {
            $hit++;
            $brow--;
        }
        if ($num[1] == $num[6]) {
            $hit++;
            $brow--;
        }
        if ($num[2] == $num[7]) {
            $hit++;
            $brow--;
        }
        if ($num[3] == $num[8]) {
            $hit++;
            $brow--;
        }
        echo $hit . " " . $brow . "\n";
    }


Measured memory_bytes: 9240
S = list(input())
ansA=0 
ansB=0
for i in range(len(S)):
    if i%2 ==0:
        if S[i] =="1" :
            ansA+=1
    else:
        if S[i] == "0":
            ansA+=1
for i in range(len(S)):
    if i%2 ==0:
        if S[i] == "0":
            ansB+=1
    else:
        if S[i] == "1":
            ansB+=1
ans = min(ansA,ansB)
print(ans)

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector <pair <pair <string,int>, int> > S(n);
    for(int i = 0; i < n; ++i){
        string s;
        int a;
        cin >> s >> a;
        S[i] = {{s,-a},i};
    }
    sort(S.begin(), S.end());
    for(auto i : S){
        cout << i.second+1 << ' ';
    }
    cout << '\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=a;i>=b;--i)
#define mem0(x) memset(x,0,sizeof(x))
#define meminf(x) memset(x,0x3f,sizeof(x))
#define VI vector<int>
#define VL vector<ll>
using namespace  std;

int main(){
    ios::sync_with_stdio(0);
    string s,t;cin>>s>>t;
    int sl = s.length(),tl = t.length();
    int cnt = tl;
    rep(i,0,sl-tl){
        int tcnt = 0;
        for(int j=0;j<=tl-1;++j){
            if(s[i+j]==t[j]){
                tcnt++;
            }
        }
        cnt = min(cnt,tl-tcnt);
    }
    cout<<cnt;
}


Measured memory_bytes: 3648