akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define N 100

int m[N][N],p[N];

int main(){
  int n,i,a,q,l,k,j;
  scanf("%d",&n);

  for(i=1;i<=n;i++){
    scanf("%d %d",&p[i-1],&p[i]);
  }

  for(i=1;i<=n;i++){
    m[i][i] = 0;
  }
  
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j = i + l - 1;
      m[i][j] = 10000000;
      for(k=i;k<=j-1;k++){
	q = m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j];
	if(m[i][j] < q){
	  m[i][j] = m[i][j];
	}else{
	  m[i][j] = q;
	}
      }
    }
  }
  
  printf("%d\n",m[1][n]);

  return 0;
}



Measured memory_bytes: 2052
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn = 1e6 + 20;
const ll mod = 1e9 + 7;
const ll prime = 196613;
int t[maxn];
int main()
{
	int n , m;
	cin >> n >> m;
	for(int i = 0; i < m; i++)
	{
		int a , b;
		cin >> a >> b;
		if(a == 1 || a == n)
			t[b]++;
		if(b == 1 || b == n)
			t[a]++;
		if(t[a] > 1 || t[b] > 1)
		{
			cout << "POSSIBLE\n";
			return 0;
		}
	}
	cout << "IMPOSSIBLE\n";
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<time.h>
#include<set>
#include<map>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
using namespace std;
typedef long long ll;
const ll INF = 1e17;
const int MOD = 1e9 + 7;


ll N,M,A[100],B[100],C,ans;

int main(void) {

	cin >> N >> M >> C;
	FOR(i, 0, M)cin >> B[i];
	
	FOR(i, 0, N) {
		ll cur = 0;
		FOR(j, 0, M) {
			cin >> A[j];
			cur += A[j] * B[j];
		}
		cur += C;
		if (cur > 0) {
			ans++;

		}
	}

	ct(ans);
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main(){
  int a, b;

  scanf("%d %d", &a, &b);
  if(a < 1 || 100 < a || b < 1 || 100 < b)
    exit(1);

  printf("%d ", a*b);
  printf("%d\n", (a+b)*2);

  return 0;
}

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


void solve(long long N, std::vector<long long> A){
  vector<int> ps = {};
  for (int i=0; i<N; i++) ps.push_back(0);

  for (int i=0; i<N-1; i++) ps[A[i]-1]++;
  for (int i=0; i<N; i++) {
    cout << ps[i] << endl;
  }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N-2+1);
    for(int i = 0 ; i < N-2+1 ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}

Measured memory_bytes: 5900
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <functional>
#define SIZE 100005

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int cnt[SIZE];
bool dp[SIZE];

int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i=0;i<n;i++) cnt[i]=1;
	memset(dp,false,sizeof(dp));
	dp[0]=true;
	for(int i=0;i<m;i++)
	{
		int a,b;
		scanf("%d %d",&a,&b);a--;b--;
		if(dp[a]) dp[b]=true;
		cnt[a]--,cnt[b]++;
		if(cnt[a]==0) dp[a]=false;
	}
	int ret=0;
	for(int i=0;i<n;i++) ret+=dp[i];
	printf("%d\n",ret);
	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<math.h>
#include <algorithm>
#include<float.h>
#include <limits>
#include <vector> 
#include <numeric>
#include <string.h>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define ll long long

using namespace::std;

int jo(ll int jxo, ll int jyo){
	ll int jhogeo = 1;
	rep(jinto,0,jyo) jhogeo=jhogeo*jxo;
	return jhogeo;
}
char tobig(char toxbig){
  return (toxbig-0x20);
}
char tolow(char toxlow){
  return (toxlow+0x20);
}
  


int main(){
  string s;
  cin>>s;
  if((s[5]<'1')&&(s[6]<'5')) cout<<"Heisei";
  else cout<<"TBD";
}
// int *p = new int[N];

//  vector<int> 変数名(要素数);
//  sort(変数名.begin(),変数名.end());//昇順ソート

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//


Measured memory_bytes: 256
x[51];main(a,b,c,d){for(a=0;a<=9;a++)for(b=0;b<=9;b++)for(c=0;c<=9;c++)for(d=0;d<=9;d++)x[a+b+c+d]++;for(;~scanf("%d",&a);printf("%d\n",x[a]));exit(0);}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi 3.14159
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    cout.tie(NULL);
    long double r;
    cin>>r;
    long double a=2*pi*r;
    cout<<a<<"\n";


    return 0;
}

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

using namespace std;

const int Nmax=1e5+2;

long long n,k,lg;
long long a[Nmax],bit[42];

long long Lgput(long long a,long long x)
{
    long long p=1;
    while(x)
    {
        if(x%2)p=p*a;
        a=a*a;
        x/=2;
    }
    return p;
}

int main()
{
    cin>>n>>k;
    for(int i=1;i<=n;i++)
        cin>>a[i];

    long long x=k;
    while(x)
    {
        bit[lg++]=x%2;
        x/=2;
    }

    long long s,bitmask=0,cnt0,cnt1,bad=0;
    for(int i=lg-1;i>=0;i--)
        if(bit[i])
        {
            cnt1=cnt0=0;
            for(int j=1;j<=n;j++)
                if(a[j] & Lgput(2,i))cnt1++;
                else cnt0++;

            if(cnt0>cnt1)bitmask+=Lgput(2,i);
            else bad=1;
        }
        else if(bad)
        {
            cnt1=cnt0=0;
            for(int j=1;j<=n;j++)
                if(a[j] & Lgput(2,i))cnt1++;
                else cnt0++;

            if(cnt0>cnt1)bitmask+=Lgput(2,i);

        }

    s=0;
    for(int i=1;i<=n;i++)
        s+=(bitmask^a[i]);

    cout<<s;
    return 0;
}


Measured memory_bytes: 1024
x,y,z,k = map(int, input().split())
a= list(map(int, input().split()))
b= list(map(int, input().split()))
c= list(map(int, input().split()))

#a.sort(reverse=True)
#b.sort(reverse=True)
#c.sort(reverse=True)

ansListab=[]
for i in range(x):
  for j in range(y):
    ansListab.append(a[i]+b[j])

ansListab.sort(reverse= True)

if len(ansListab)>k:
  ansListab=ansListab[0:k]

ansList=[]

for i in c:
  for j in ansListab:
    ansList.append(i+j)

ansList.sort(reverse= True)

for i in range(k):
  print(ansList[i])


Measured memory_bytes: 134920
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include<iostream>
using namespace std;

#define int long long int
#define all(x) x.begin(),x.end()
#define endl '\n'

#ifndef ONLINE_JUDGE
template<typename T>		
void __p(T a) {
  cerr<<a;
}
template<typename T, typename F>
void __p(pair<T, F> a) {
  cerr<<"[";
  __p(a.first);
  cerr<<",";
  __p(a.second);
  cerr<<"]";
}
template<typename T>
void __p(std::vector<T> a) {
  cerr<<"[";
  for(auto it=a.begin(); it<a.end(); it++)
    __p(*it),cerr<<",]"[it+1==a.end()];
}
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) {
  __p(a1);
  __p(a...);
}
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
  cerr<<name<<" : ";
  __p(arg1);
  cerr<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
  int bracket=0,i=0;
  for(;; i++)
    if(names[i]==','&&bracket==0)
      break;
    else if(names[i]=='(')
      bracket++;
    else if(names[i]==')')
      bracket--;
  const char *comma=names+i;
  cerr.write(names,comma-names)<<" : ";
  __p(arg1);
  cerr<<" | ";
  __f(comma+1,args...);
}
#define trace(...) cerr<<"Line:"<<__LINE__<<" ", __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...)
#endif

const int mod=1e9+7;
void test_case(){
	int n;
	cin>>n;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	vector<int> pref(n);
	for(int i=1;i<n;i++){
		pref[i]=pref[i-1]+a[i-1];
	}
	trace(pref);
	int ans=0;
	for(int i=0;i<n;i++){
		(ans+=(a[i]%mod)*(pref[i]%mod))%=mod;
	}
	cout<<ans;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
 
    int T=1;
    //cin>>T;
    for(int TT=1; TT<=T; TT++){
        test_case();
    }

    cerr<<endl<<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n";

    return 0;
}


Measured memory_bytes: 6360
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;

struct Point {
  double x;
  double y;
};

double norm(Point a, Point b) {
  return sqrt( pow(a.x - b.x, 2) + pow(a.y - b.y, 2) );
}

double dot(Point p0, Point p1, Point p2) {
  return (p1.x - p0.x) * (p2.x - p0.x) + (p1.y - p0.y) * (p2.y - p0.y);
}

double cross(Point p0, Point p1, Point p2) {
  return ( p1.x - p0.x ) * ( p2.y - p0.y ) - ( p2.x - p0.x) * (p1.y - p0.y);
}

int main(void) {
  int q;
  Point p0, p1, p2;
  cin >> p0.x >> p0.y >> p1.x >> p1.y;
  cin >> q;

  for(int i = 0; i < q; i++) {
    cin >> p2.x >> p2.y;
    double cro = cross(p0, p1, p2);
    //printf("cro = %lf\n", cro);
    if(cro > 0) 
      printf("COUNTER_CLOCKWISE\n");
    else if(cro < 0)
      printf("CLOCKWISE\n");
    else {
      double norm10 = norm(p1, p0);
      double norm20 = norm(p2, p0);
      //printf("%lf %lf\n", norm10, norm20);
      if(norm20 == 0) {
        printf("ON_SEGMENT\n");
        continue;
      }
      double cos = dot(p0, p1, p2) / ( norm10 * norm20 );
      if(cos >= 0) {
        if( norm10 < norm20)
          printf("ONLINE_FRONT\n");
        else 
          printf("ON_SEGMENT\n");
      }
      else {
        printf("ONLINE_BACK\n");
      }
    }
  }
}


Measured memory_bytes: 3228
#include<iostream>
#include<map>
#include<vector>
#include<cmath>
using namespace std;

int main() {
    long big = 1e6+10;
    long N, P;
    cin>>N>>P;
    map<long, long> prime;
    vector<long> primearr;
    for(int i=2;i<=big;++i){
        while(P%i==0){
            if(prime[i]==0)primearr.push_back(i);
            prime[i]++;
            P /= i;
        }
    }
    if(P!=1){
        primearr.push_back(P);
        prime[P]++;
    }
    long ans = 1;
    for(long i=0;i<primearr.size();++i){
        if(prime[primearr[i]]/N>0){
            ans *= pow(primearr[i], (prime[primearr[i]]/N));
        }
    }
    cout<<ans<<endl;
}


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


const ll MOD = 1e9 + 7;
template<ll MOD> struct ModInt {
    ll value;
    ModInt() : value(0) {}
    ModInt(const ll& v) : value(v % MOD) {
        if ( value < 0 ) value += MOD;
    }
    ModInt<MOD>& operator=(const ModInt& o) {
        value = o.value;
        return *this;
    }
    inline bool operator==(const ModInt& o) {
        return value == o.value;
    }
    inline bool operator!=(const ModInt& o) {
        return value != o.value;
    }
    ModInt<MOD>& operator+=(const ModInt& o) {
        value += o.value;
        if ( value >= MOD ) value -= MOD;
        return *this;
    }
    ModInt<MOD>& operator-=(const ModInt& o) {
        value += MOD - o.value;
        if (value >= MOD ) value -= MOD;
        return *this;
    }
    ModInt<MOD>& operator*=(const ModInt& o) {
        value *= o.value;
        value %= MOD;
        return *this;
    }
    ModInt<MOD>& operator/=(const ModInt& o) {
        value *= inverse(o.value);
        value %= MOD;
        return *this;
    }
    ModInt<MOD> operator-() {
        return ModInt<MOD>(-value);
    }
    ModInt<MOD> operator+(const ModInt& o) {
        ModInt<MOD> r(*this);
        r += o;
        return r;
    }
    ModInt<MOD> operator-(const ModInt& o) {
        ModInt<MOD> r(*this);
        r -= o;
        return r;
    }
    ModInt<MOD> operator*(const ModInt& o) {
        ModInt<MOD> r(*this);
        r *= o;
        return r;
    }
    ModInt<MOD> operator/(const ModInt& o) {
        ModInt<MOD> r(*this);
        r /= o;
        return r;
    }
    ModInt<MOD> pow(ll n) {
        ModInt<MOD> t(*this), r = 1;
        while ( n > 0 ) {
            if ( n & 1 ) r *= t;
            t *= t;
            n >>= 1;
        }
        return r;
    }
private:
    ll inverse(ll a) {
        ModInt<MOD> t(a);
        return t.pow(MOD - 2).value;
    }
};
template<ll MOD> std::ostream& operator<< (std::ostream& os, const ModInt<MOD>& o) {
    os << o.value;
    return os;
}
template<ll MOD> std::istream& operator>> (std::istream& is, ModInt<MOD>& o) {
    is >> o.value;
    return is;
}

using Int = ModInt<MOD>;

ll solve() {
    ll N;
    cin >> N;
    Int ans = Int(10).pow(N) - Int(9).pow(N) * 2 + Int(8).pow(N);
    return ans.value;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3588
// Package main provides
//
// File:  c.go
// Author: ymiyamoto
//
// Created on Sat Jan 26 13:33:14 2019
//
package main

import (
	"fmt"
)

func pow(n, m int) int {
	if m == 0 {
		return 1
	}
	return n * pow(n, m-1)
}

func min(slice ...int) int {
	ret := slice[0]
	for _, s := range slice {
		if s < ret {
			ret = s
		}
	}
	return ret
}

func main() {
	var N int
	fmt.Scan(&N)

	dp := make([]int, N+1)
	for i := range dp {
		dp[i] = i
	}

	for i := range dp {
		for j := 6; i+j <= N; j *= 6 {
			dp[i+j] = min(dp[i+j], dp[i]+1)
		}
		for j := 9; i+j <= N; j *= 9 {
			dp[i+j] = min(dp[i+j], dp[i]+1)
		}
	}

	fmt.Println(dp[N])
}


Measured memory_bytes: 1280
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
using namespace std;

#define LL long long
#define DB double
#define MAXN 100
#define MOD 1000000007
#define Pr pair<int,int>
#define X first
#define Y second
#define INF 1000000000000000000
#define mem(x,v) memset(x,v,sizeof(x))

LL read(){
	LL x=0,F=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')F=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
	return x*F;
}

int n,a[MAXN+5],ans;
int dp[MAXN+5][MAXN+5][MAXN+5];

int add(int a,int b){return (a+b>=MOD)?a+b-MOD:a+b;}
int dec(int a,int b){return (a-b<0)?a-b+MOD:a-b;}
int mul(int a,int b){return (1LL*a*b)%MOD;}
void upd(int &a,int b){a=add(a,b);}

int main(){
	n=read();
	for(int i=1;i<=2*n-1;i++)a[i]=read();
	sort(a+1,a+2*n);
	dp[n][1][0]=1;
	for(int i=n-1;i>=1;i--){
		int al=(a[i+1]!=a[i]),ar=(a[2*n-i-1]!=a[2*n-i]);
		for(int l=0;l<=2*n-1;l++)
			for(int r=0;l+r<=2*n-1;r++)
			if(dp[i+1][l][r]){
				for(int dl=1;dl<=l+al;dl++)
				upd(dp[i][l+al-dl+1][r+ar+(dl>1)],dp[i+1][l][r]);//将不走的情况合并在里面 
				for(int dr=1;dr<=r+ar;dr++)
				upd(dp[i][l+al+1][r+ar-dr],dp[i+1][l][r]);
			}
	}
	for(int l=0;l<=2*n-1;l++)
		for(int r=0;l+r<=2*n-1;r++)
		ans=add(ans,dp[1][l][r]);
	printf("%d\n",ans);
}

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

bool e[2020][2020];

bool ok(stack<int> s){
    int t = s.top();
    s.pop();
    vector<int> ans;
    int k=-1;
    while(!s.empty()){
        k = s.top();s.pop();
        ans.push_back(k);
        if(k==t) break;
    }
    if(k!=t) return false;
    if(ans.size()==0) return false;
    reverse(ans.begin(),ans.end());
    bool pos = true;
    for(int i=0;i<ans.size();i++){
        for(int j=0;j<ans.size();j++){
            int g = ans.size();
            if(i==j) continue;
            if(j == ((i+1)%g)) continue;
            if(e[ans[i]][ans[j]]) pos = false;
        }
    }
    return pos;
}

vector<vector<int>> v(2020);
bool used[2020];
bool used2[2020];
bool can = false;
vector<int> res;

stack<int> st;

bool dfs(int p){
    used[p] = true;
  	used2[p] = true;
    st.push(p);
    if(can) return true;
    for(auto i:v[p]){
        if(!used[i]){
            if(dfs(i)) return true;
            
        }
        else if(used2[i]){
            if(st.size()<=2) continue;
            st.push(i);
            bool pos = ok(st);
            if(pos){
                can = true;
                int t = i;
                st.pop();
                res.push_back(t);
                while(!st.empty()){
                    int k = st.top();
                    st.pop();
                    cerr << st.size() << " " << k << endl;
                    if(k==t) break;
                    res.push_back(k);
                }
                return true;
            }
            st.pop();
        }
    }
    st.pop();
    return false;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    
    int n,m;
    cin>>n>>m;
    if(m==0){
        cout << -1 << endl;
        return 0;
    }
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        a--,b--;
        e[a][b]=1;
        v[a].push_back(b);
    }
    for(int i=0;i<n;i++){
        if(!used[i] && !can){
            for(int j=0;j<1010;j++) used2[j] = false;
            st = stack<int>();
            dfs(i);
        }
    }
    if(!can || res.size()==0){
        cout << -1 << endl;
        return 0;
    }
    reverse(res.begin(),res.end());
    cout << res.size() << endl;
    for(auto i:res){
        cout << i+1 << "\n";
    }


}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
int g[10][10];
using namespace std;

int main(){
  int H,W;
  cin>>H>>W;
  for(int i=0;i<10;i++)for(int j=0;j<10;j++)cin>>g[i][j];
  std::vector<int> v(H*W);
  for(int i=0;i<H*W;i++)cin>>v[i];
  std::vector<int> a(10);
  for(int i=0;i<10;i++)a[i]=g[i][1];
  for(int k=0;k<10;k++){
    for(int i=0;i<10;i++){
      for(int j=0;j<10;j++){
        a[i]=min(a[i],g[i][j]+a[j]);
      }
    }
  }
  int ans=0;
  for(int i=0;i<H*W;i++){
    if(v[i]!=-1){
      ans+=a[v[i]];
    }
  }
  cout<<ans<<endl;
}


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


struct Mo{
  using F = function<void(int)>;
  vector<int> ls,rs,ord;
  int n,width,nl,nr,ptr;
  F expandL,expandR;
  F shrinkL,shrinkR;

  Mo(int n,int width,F expandL,F expandR,F shrinkL,F shrinkR):
    n(n),width(width),nl(0),nr(0),ptr(0),
    expandL(expandL),expandR(expandR),
    shrinkL(shrinkL),shrinkR(shrinkR){}

  Mo(int n,int width,F expand,F shrink){
    *this=Mo(n,width,expand,expand,shrink,shrink);
  }

  void add(int l,int r){
    ls.emplace_back(l);
    rs.emplace_back(r);
  }

  void build(){
    ord.resize(ls.size());
    iota(ord.begin(),ord.end(),0);
    sort(ord.begin(),ord.end(),
         [&](int a,int b){
           if(ls[a]/width!=ls[b]/width) return ls[a]<ls[b];
           if(rs[a]==rs[b]) return ls[a]<ls[b];
           return bool((rs[a]<rs[b])^((ls[a]/width)&1));
         });
  }

  int process(){
    if(ptr==(int)ord.size()) return -1;
    const int idx=ord[ptr++];
    while(nl>ls[idx]) expandL(--nl);
    while(nr<rs[idx]) expandR(nr++);
    while(nl<ls[idx]) shrinkL(nl++);
    while(nr>rs[idx]) shrinkR(--nr);
    return idx;
  }
};


template<typename T=int>
vector<T> read(size_t n){
  vector<T> ts(n);
  for(size_t i=0;i<n;i++) cin>>ts[i];
  return ts;
}

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  int n,q;
  cin>>n>>q;
  auto cs=read(n);

  int num=0;
  vector<int> cnt(n+1);
  auto expand=[&](int k){
    num+=cnt[cs[k]]++==0;
  };
  auto shrink=[&](int k){
    num-=--cnt[cs[k]]==0;
  };

  Mo mo(n,1000,expand,shrink);
  for(int i=0;i<q;i++){
    int l,r;
    cin>>l>>r;
    l--;
    mo.add(l,r);
  }
  mo.build();

  vector<int> ans(q);
  for(int i=0;i<q;i++){
    int k=mo.process();
    ans[k]=num;
  }

  for(int a:ans) cout<<a<<newl;
  return 0;
}


Measured memory_bytes: 15708
#include<bits/stdc++.h>
using namespace std;
double a[15],b;
signed main(void){
	while(scanf("%lf,",&a[1])!=EOF){
		for(int i=2;i<12;i++)
			scanf("%lf,",&a[i]);
		scanf("%lf",&a[12]);
		b=0;
		for(int i=1;i<=10;i++)
			b+=a[i];
		b=(b*a[11])/(a[11]+a[12]);
		for(int i=1;i<=10;i++){
			b-=a[i];
			if(b<=0){
				printf("%d\n",i);
				break;	
			}
		}
	}
}

Measured memory_bytes: 1208
from copy import copy
n = int(input())
a_ls = list(map(int, input().split()))
c_bin = [[0]*60 for _ in range(n)]
a_bin_ls = [[0]*60 for _ in range(n)]
now_bin = [0] * 60
for i in range(n-1,-1,-1):
    a = a_ls[i]
    j = 0
    while True:
        if a == 1:
            now_bin[j] += 1
            a_bin_ls[i][j] = 1
            break
        elif a == 0:
            break
        a,r = divmod(a,2)
        now_bin[j] += r 
        a_bin_ls[i][j] = r
        j += 1
    c_bin[i] = copy(now_bin)
ans_bin = [0]*60
for i in range(n-1):
    a_bin = a_bin_ls[i]
    for j in range(60):
        if a_bin[j] == 0:
            times = c_bin[i+1][j]
        else:
            times = n - (i+1) - c_bin[i+1][j]
        ans_bin[j] += times
ans = 0
mod = 10**9+7
for i in range(60):
    ans += 2**i * (ans_bin[i]%mod)
    ans %= mod
print(ans)




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

int main() {
  string S,T;
  cin >> S >> T;
  int c = 0;
  for(int i = 0;i<3;i++){
    if(S[i] == T[i]) c++;
  }
  cout << c << endl;
}


Measured memory_bytes: 256
/*
 * short          2^15-1 ~ 3e4
 * int, long x86  2^31-1 ~ 2e9
 * long long      2^63-1 ~ 9e18
 */
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define fr(a, b) for (int a = 0; a < b; ++a)
using namespace std; typedef long long ll; const int inf = numeric_limits<int>::max(); void print() {cerr << endl;}
template<typename T, typename... Ts> void print(T&&a, Ts&&...etc) {cerr << a << ' '; print(etc...);}
template<typename T, typename U> ostream& operator<<(ostream& s, const pair<T,U>&p) {s << "<" << p.x << ", " << p.y << ">"; return s;}
template<typename T> ostream& operator<<(ostream& s, const vector<T>&v) {s << "["; for (auto &x : v) s << x << ", "; if (!v.empty()) s << "\b\b"; s << "]"; return s;}
struct io{io(){ios_base::Init i; ios_base::sync_with_stdio(0); cin.tie(0);}}io;

bool ok(int a, int b) {
    return abs(a - b) < 2;
}

void next_ll(vector<int> &a) {
    int n = (int)a.size();
    bool f = false;
    fr(i, n) {
        if (a[i] < 9 && (i == n-1 || ok(a[i]+1, a[i+1]))) {
            a[i]++;
            for (int j = i-1; j >= 0; --j) {
                a[j] = max(0, a[j+1]-1);
            }
            f = true;
            break;
        }
    }
    if (!f) {
        fr(i, n) a[i] = 0;
        a.pb(1);
    }
}

int main() {
    int k;
    cin >> k;
    vector<int> a(1, 1);
    fr(i, k-1) {
        next_ll(a);
    }
    for (int i = a.size()-1; i >= 0; --i) {
        cout << a[i];
    }
    cout << endl;
}


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

int main() {
    int t=1;
    //cin >> t;
    while(t--){
        int n,i,j;
        cin >> n;
        string s;
        cin >> s;
        i=0;
        j=n-1;
        int cnt=0;
        while(i<j){
            if(s[i]=='W' && s[j]=='R'){
                cnt++;
                s[i]='R';
                s[j]='W';
                i++;
                j--;
            }else if(s[i]=='W' && s[j]!='R'){
            	
                j--;
            }else if(s[i]=='R' && s[j]=='R'){
                i++;
                //j--;
            }else{
            	i++;
            	j--;
            }
        }
        int cntc=0;
        for(i=0;i<n;i++){
        	if(s[i]=='R'&&cntc>=1){
        		cnt++;
        	}
        	if(s[i]=='W'){
        		cntc++;
        	}
        }
        cout << cnt;
    }
}

Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll field[505][505]={0};
int main(){
  ll n;
  cin>>n;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
      char c;
      cin>>c;
      if(c=='.') field[i][j]=1;
    }
  }
  ll completed=0;
  bool fk=true;
  for(int j=1;j<=n;j++){
    int cnt=0;
    for(int i=1;i<=n;i++) cnt+=field[i][j];
    if(cnt!=0) completed++;
    if(cnt!=n) fk=false;
  }
  if(fk){
    cout<<-1<<endl;
    return 0;
  }
  ll ans=17441744;
  for(int i=1;i<=n;i++){
    bool f=false;
    int cnt=0;
    for(int j=1;j<=n;j++){
      if(field[j][i]==0) f=true;
      cnt+=field[i][j];
    }
    if(!f) cnt++;
    ans=min(ans,cnt+completed);
  }
  if(ans==17441744) cout<<-1<<endl;
  else cout<<ans<<endl;
}


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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,n) for(int i=1; i<=(n); i++)
#define pii pair<int,int>
#define gsort(x,n) sort((x),(x)+(n),greater<int>())
#define all(x) (x).begin(), (x).end()
#define int long long
#define abs(a) llabs(a)
#define re(s) reverse((s).begin(),(s).end())
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
const long long mod = 1000000007;

using namespace std;
signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n,cnt=0;
    cin>>n;
    int x[1000010];

    rep(i,n) cin>>x[i];

    sort(x,x+n);

    cout<<x[n/2]-x[n/2-1]<<'\n';
}

Measured memory_bytes: 2944
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    void Calc()
    {
        var sc = new Scanner();
        int N = sc.NextInt();
        int a = 0;
        string C = Console.ReadLine();
        string D = Console.ReadLine();
        if (C == D)
        {
            Console.WriteLine(N);
        }
        if (N == 1 && C != D)
        {
            {
                Console.WriteLine(2);
            }
        }
        if (N != 1 && C != D)
        {
            for (int i = 1; i < N; i++)
            {
                if (D.Substring(0, i) == C.Substring(N - i))
                {
                    a = i;
                }
            }
            Console.WriteLine(N * 2 - a);
        }

    }

    static void Main()
    {
        new Program().Calc();
    }

    class Scanner
    {
        string[] s = new string[0];
        int i = 0;
        char[] cs = new char[] { ' ' };

        public string Next()
        {
            if (i < s.Length) return s[i++];
            s = Console.ReadLine().Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return s[i++];
        }
        public int NextInt() { return int.Parse(Next()); }
        public long NextLong() { return long.Parse(Next()); }
        public double NextDouble() { return double.Parse(Next()); }
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;

int main() {

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

    vector< long long int > a, f;

    for ( long long int i = 0; i < n; i++ ) {
        long long int in;
        cin >> in;
        a.push_back( in );
    }
    for ( long long int i = 0; i < n; i++ ) {
        long long int in;
        cin >> in;
        f.push_back( in );
    }

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

    long long int ma = 1145140LL * 1145140LL;
    long long int mi = -1;

    while( true ) {
        long long int p = ( ma + mi ) / 2;
        long long int cnt = 0;
        for ( long long int i = 0; i < n; i++ ) {
            long long int q = p / f[n-1-i];
//            if ( ( p % f[n-1-i] ) != 0 ) q++;
            if ( a[i] <= q ) continue;
            cnt += ( a[i] - q );
        }
        if ( cnt <= k ) {
            ma = p;
        } else {
            mi = p;
        }
        if ( ma == mi + 1 ) {
            cout << ma << endl;
            return 0;
        }
    }

    return 0;

}


Measured memory_bytes: 6384
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    vl a(n);
    ll ma = -1;  // aの中で絶対値が最大の数
    ll id = -1;  // aの中で絶対値が最大の数のindex
    rep(i, n) {
        cin >> a[i];
        if(ma < abs(a[i])) {
            ma = abs(a[i]);
            id = i+1;
        }
    }

    out(2*(n-1));
    // aの中で絶対値が最大の数を他の数に足しまくる
    exrep(i, 1, n) {
        if(i == id) {
            continue;
        }
        cout << id << " " << i << "\n";
    }
    
    if(a[id-1] > 0) {  // a[id]を足した後のaの要素が全て正のとき
        // 左から累積和
        exrep(i, 1, n-1) {
            cout << i << " " << i+1 << "\n";
        }
    }
    else {  // a[id]を足した後のaの要素が全て0以下のとき
        // 右から累積和
        for(ll i = n-1; i >= 1; i--) {
            cout << i+1 << " " << i << "\n";
        }
    }

    re0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"bytes"
	"fmt"
	"os"
	"strconv"
	"strings"
)

type node struct {
	prev, next *node
	key        int
}

var dummy = &node{}

func initNode() {
	dummy.next = dummy
	dummy.prev = dummy
}

// insert inserts the new node at the top position of node.
func insert(key int) {
	new := &node{key: key}
	new.next = dummy.next
	dummy.next.prev = new
	dummy.next = new
	new.prev = dummy
}

// search finds and returns the first node containing the specified key.
func search(key int) *node {
	current := dummy.next
	for current.key != key {
		if current == dummy {
			return nil
		}
		current = current.next
	}
	return current
}

// deleteNode deletes specified node.
func deleteNode(n *node) {
	if n == nil {
		return
	}
	n.prev.next = n.next
	n.next.prev = n.prev
	n = nil
}

func deleteFirst() {
	deleteNode(dummy.next)
}

func deleteLast() {
	deleteNode(dummy.prev)
}

func printList() string {
	buf := bytes.Buffer{}
	current := dummy.next
	for {
		buf.WriteString(strconv.Itoa(current.key))
		current = current.next
		if current == dummy {
			break
		}
		buf.WriteString(" ")
	}
	return buf.String()
}

func main() {
	n := 0
	sc := bufio.NewScanner(os.Stdin)
	if sc.Scan() {
		n, _ = strconv.Atoi(sc.Text())
	}
	initNode()
	nodeKey := 0
	for i := 0; i < n; i++ {
		sc.Scan()
		ss := strings.Fields(sc.Text())
		switch ss[0] {
		case "insert":
			nodeKey, _ = strconv.Atoi(ss[1])
			insert(nodeKey)
		case "delete":
			nodeKey, _ = strconv.Atoi(ss[1])
			if target := search(nodeKey); target != nil {
				deleteNode(target)
			}
		case "deleteFirst":
			deleteFirst()
		case "deleteLast":
			deleteLast()
		default:
			fmt.Println("specify the command form the following list: \"insert <key>\", \"delete <key>\", \"deleteFirst\", \"deleteLast\"")
			os.Exit(1)
		}
	}
	fmt.Println(printList())
}



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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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;
  vector<int> A(N); REP(i, N) cin >> A[i];
  vector<int> tmp_A; tmp_A = A;
  sort(all(tmp_A));
  int max_n = tmp_A[N - 1];
  int max_n2 = tmp_A[N - 2];

  REP(i, N) {
    if(A[i] == max_n) {
      cout << max_n2 << endl;
    } else {
      cout << max_n << endl;
    }
  }
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
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;}
const int inf = 1001001001;

int main() {
    int n[32] = {1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51};
    int k;
    cin >> k;
    cout << n[k-1] << endl;
}

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

string a, b;
int ans = INT_MAX;

int main(){
	cin >> a >> b;
	for (int i = 0; i <= a.size() - b.size(); i++){
        int sum = 0;
        for (int j = i; j < i + b.size(); j++)
            if (a[j] != b[j - i])
                sum++;
        ans = min(ans, sum);
    }
    printf("%d\n", ans);
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    int x[n], y[n], h[n], s = 0;
    for(int i = 0; i < n; i++){
        cin >> x[i] >> y[i] >> h[i];
        if(h[i] > 0) s = i;
    }
    for(int i = 0; i <= 100; i++){
        for(int j = 0; j <= 100; j++){
            bool flag = true;
            int top = h[s] + abs(j - x[s]) + abs(i - y[s]);
            for(int k = 0; k < n; k++){
                int d = max(0, top - abs(j - x[k]) - abs(i - y[k]));
                if(d != h[k]) flag = false;
            }
            if(flag){
                cout << j << " " << i << " " << top << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
X = list(map(int,input().split()))
S = []
for i in range(n-k+1):
	if X[i]*X[i+k-1] < 0:
		S.append(X[i+k-1]-X[i]+min(abs(X[i+k-1]),abs(X[i])))
	else:
		S.append(max(abs(X[i+k-1]),abs(X[i])))
print(min(S))

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


int main(void){
    int k,s;
    cin >> k >> s;
    int count = 0;
    int z = 0;
    rep (i,k){
        rep (j,k){
            z = s - (i + j);
            if(0<= z && z<=k) count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <iomanip>
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;

using namespace std;

int main()
{
	int n;
	int d;
	cin >> n >> d;
  int range;
	int ans;
	range = d * 2 + 1;
	if (n % range == 0) {
		ans = n / range;
	} else {
		ans = n / range + 1;
	}
	cout << ans;
	return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int P[] = new int[N];
		int result = 1;

		for (int i = 0; i < N; i++) {
			P[i] = scan.nextInt();
		}

		int min = P[0];
		for (int i = 1; i < N; i++) {
				if (min > P[i]) {
					min = P[i];
					result++;
				}
			}

		System.out.println(result);

	}

}


Measured memory_bytes: 76984
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // min, max, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>
using namespace std;
#define rep(i,n) rep1(i,0,n)
#define rep1(i,m,n) for(int i=m;i<(n);i++)
#define All(v) (v).begin(),(v).end()
using ll = long long;
const int inf = 1<<30;
const ll mod = 1000000007;
const ll INF = 100000000000000000LL;
const double PI = acos(-1);
int main(){
    int n,q;
    cin >> n >> q;
    string s;
    cin >> s;
    int d[1000000];
    rep(i, n + 10) d[i] = 0;
    rep1(i,1,n){
        if(s[i-1]=='A'&&s[i]=='C')
            d[i] = 1;
    }
    rep1(i, 1, n) d[i] += d[i - 1];
    rep(i, q)
    {
        int l, r;
        cin >> l >> r;
        cout << d[r-1] - d[l - 1] << endl;
    }
}

Measured memory_bytes: 3200
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import random
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def main():

	N = int(input())
	#S = list(input())
	#A,B,C,D = map(int, input().split(" "))
	#L = list(map(int, input().split(" ")))

	AB = []
	for i in range(N):
		a, b = map(int, input().split(" "))
		AB.append((a,b))

	AB = sorted(AB, key=lambda x:(x[1]))

	time = 0
	for i, val in enumerate(AB):
		a,b = val
		time += a
		if time > b:
			print("No")
			sys.exit()

	print("Yes")




if __name__ == "__main__":
	main()

Measured memory_bytes: 34292
#include <stdio.h>
#include <stdlib.h>

int **vv;
int *kk;
int *dist;

void walk(int k, int d)
{
  int i, j;
  for (j=0; j<kk[k]; j++) {
    i = ((int*)vv[k])[j]-1;
    if (dist[i]<0 || (dist[i]>0 && dist[i]>d))
      dist[i] = d;
    else continue;
    walk(i, d+1);
  }
}

int main()
{
  int i, j, n;
  fscanf(stdin, "%d", &n);

  dist = (int*)malloc(sizeof(int)*n);
  kk =   (int*)malloc(sizeof(int)*n);
  dist[0] = 0;
  for (i=1; i<n; i++)  dist[i] = -1;

  vv = (int **)malloc(sizeof(int*)*n);
  for (i=0; i<n; i++) {
    fscanf(stdin, "%*d %d", &kk[i]);
    vv[i] = (int*)malloc(sizeof(int)*(kk[i]));
    for (j=0; j<kk[i]; j++)  scanf("%d",  &vv[i][j]);
  }

  walk(0, 1);

  for (i=0; i<n; i++)  printf("%d %d\n", i+1, dist[i]);
  return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
bool C(vector<int>& v, int w, int m){
  int index = 0;
  for(int i = 0; i < m && index < v.size(); i++){
    int count = 0;
    while(index < v.size() && count + v[index] <= w){
      count += v[index++];
    }
  }
  if(index == v.size()) return true;
  else return false;
}

int main(){
  int m,n;
  while(cin>>m>>n,m){
    vector<int> thick(n);
    REP(i,n)cin>>thick[i];
    int up = 15000000;
    int lw = 1;
    while(up - lw > 0){
      int mid = (up + lw) /2;
      if(C(thick,mid,m)){
        up = mid;
      }else{
        lw = mid + 1;
      }
    }
    cout<<up<<endl;
  }
  return 0;
}

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

int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	if(a+b>16)printf(":(\n");
	else
	{
		if(a<=8&&b<=8)printf("Yay!\n");
		else printf(":(\n");
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main() {
  string s,a;
  int cnt=0;
  cin>>s;
  a="CODEFESTIVAL2016";
  for(int i=0;i<s.size();i++){
    if(s[i]!=a[i]) cnt++;
  }
  cout<<cnt<<endl;
}


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

const int N = 2e5 + 7;

vector<int> arr[N];
vector<int> val(N,0);
vector<int> ans(N);
bool seen[N];

void sol(int v,int value){
	ans[v] = val[v] + value;
	seen[v] = true;
	
	for(int i = 0;i < arr[v].size();i++){
		if(!seen[arr[v][i]]) sol(arr[v][i], value + val[v]);
	}

}


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

	int n,q;
	cin >> n >> q;

	memset(seen, false,sizeof(seen));

	for(int i = 0;i < n-1;i++){
		int u,v;
		cin >> u >> v;

		arr[u-1].push_back(v-1); arr[v-1].push_back(u-1);
	}

	while(q--){
		int p,x;
		cin >> p >> x;

		val[p-1] += x;
	}

	sol(0, 0);

	for(int i = 0;i < n;i++) cout << ans[i] << " ";

}

Measured memory_bytes: 24448
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1001001001;

int main() {
  ll x, k, d;
  cin >> x >> k >> d;
  x = abs(x);
  ll ans;
  if(x/d >= k) {
    ans = x - k * d;
  } else {
    k -= x/d;
    x = x%d;
    if(k%2 == 1) x = abs(x-d);
    ans = x;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3640
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	int k;
	cin >> k;
	int len = (int) s.length();
	set<string> st;
	for (int i = 0; i < len; i++) {
		string t;
		for (int j = i; j < len; j++) {
			if ((int) t.length() > k) break;
			t += s[j];
			st.insert(t);
		}
	}
	int cnt = 0;
	for (auto i : st) {
		cnt++;
		if (cnt == k) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;	
}

Measured memory_bytes: 2176
//C
#include <bits/stdc++.h>
using namespace std;
vector<int> L(100010);
vector<int> R(100010);

int main(){
    int N,M;
    cin >> N >> M;
    for(int i = 0;i<M;i++){
        cin >> L[i];
        cin >> R[i];
    }

    int maxL, minR;
    maxL = L[0]; minR = R[0];
    for(int i = 0;i<M;i++){
        if(L[i] > maxL) maxL = L[i];
        if(R[i] < minR) minR = R[i];
    }
    int ans = 0;
    if(maxL>minR){ ans = 0;}
    else {
        for(int i = maxL;i<=minR;i++) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
line = input()

if int(line) >= 100:
    num = int(line[-2:])
    item_number = int(line[:-2])



    res_list = []
    a = 5
    while True:
        if num == 0:
            break
        for _ in range(num//a):
            res_list.append(a)

        num = num % a

        if 1<= num <= 4:
            res_list.append(num)
            break


    # print(res_list)

    if len(res_list) > item_number:
        print(0)
    else:
        print(1)

else:
    print(0)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e18
#define p2(a) (1 << (a))

int main() {
    int L;
    cin >> L;
    int N = (int)log2(L) + 1;
    vector<tuple<int, int, int>> e;
    for (int i = 1; i < N; i++) {
        e.push_back(make_tuple(i, i + 1, p2(i - 1)));
        e.push_back(make_tuple(i, i + 1, 0));
    }
    for (int i = N - 1; i >= 0; i--) {
        if (L - p2(i - 1) >= p2(N - 1)) {
            e.push_back(make_tuple(i, N, L - p2(i - 1)));
            L -= p2(i - 1);
        }
    }
    cout << N << " " << e.size() << endl;
    for (const auto& t : e) cout << get<0>(t) << " " << get<1>(t) << " " << get<2>(t) << endl;
    return 0;
}

Measured memory_bytes: 384
import heapq
N, M = [int(i) for i in input().split()]
A = [-int(i) for i in input().split()]
heapq.heapify(A)
for i in range(M):
    a = heapq.heappop(A)
    a = -a//2
    heapq.heappush(A, -a)

print(-sum(A))

Measured memory_bytes: 14180
import sys
from collections import defaultdict
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

n,k = map(int, input().split())
p = list(map(int, input().split()))

d = defaultdict(float)
for i in range(1, 1001):
    j = i
    while 0 < j:
        t = j * (1 / i)
        d[i] += t
        j -= 1

sum = [0.0]*(n+1)
for i in range(n):
    sum[i+1] = sum[i] + d[p[i]]

ans = 0
for i in range(k-1, n+1):
    tmp = sum[i] - sum[i-k]
    ans = max(ans,tmp)

print('{:.12f}'.format(ans))


Measured memory_bytes: 102032
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        String str  = sc.nextLine();
        String[] astr = str.split(" "); //状況に合わせて
        int[] in_data = Stream.of(astr).mapToInt(x->{
            try{
                return Integer.parseInt(x);
            }
            catch(Exception e){
                e.printStackTrace();
            }
            return 0;
        }).toArray();
        sc.close();
        int[] arr = new int[n];
        for(int i=0;i<in_data.length;i++){
            arr[in_data[i]-1] = i+1;
        }
        for(int j: arr){
            System.out.print(j+" ");
        }
    }
}

Measured memory_bytes: 52784
#include <bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define LL long long int
using namespace std;

const int N = 1e5 + 5;
const int oo = 1e9 + 5;
const int MOD = 998244353;

void solve() {
    int n;
    cin >> n;
    map<LL, int> mp;
    LL sum = 0;
    for (int i=0;i<n;++i) {
        LL x;
        cin >> x;
        mp[x]++;
        sum += x;
    }
    int q;
    cin >> q;
    while(q--) {
        LL b, c;
        cin >> b >> c;
        LL cnt = mp[b];
        sum -= b * cnt;
        sum += c * cnt;
        mp[c] += cnt;
        mp[b] = 0;
        cout << sum << '\n';
    }
} 

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

Measured memory_bytes: 9408
/*input
9999 10
540 7550
691 9680
700 9790
510 7150
415 5818
551 7712
587 8227
619 8671
588 8228
176 2461
*/

#include <bits/stdc++.h>

using namespace std;

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

	int h, n;
	cin >> h >> n;
	vector<pair<long long, long long>> v(n+1);
	for(int i = 1; i <= n; i++) {
		cin >> v[i].first >> v[i].second;
	}
	vector<long long> dp(h+1);
	for(int i = 1; i <= h; i++) {
		long long temp = 1e15;
		for(int j = 1; j <= n; j++) {
			if(i < v[j].first) temp = min(temp, v[j].second);
			else temp = min(temp, dp[i-v[j].first] + v[j].second);
		}
		dp[i]= temp;
	}
	cout << dp[h] << '\n';
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int N;
  cin >>N;
  int H[N];
  rep(i,N) cin>>H[i];
  
  int vec[N]={0};
  for(int i=1;i<N;i++) {
    vec[i]=H[i-1]-H[i];
  }
  
  int mx=0;
  int ans=0;
  
  for(int i=1;i<N;i++){
    if(vec[i]>=0){
      mx++;
      ans=max(ans,mx);
    }
    else {
      mx=0;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll __int128
#define inf (ll)2333333333333333333

map<ll,ll> mp;

ll t,n,a,b,c,d;

inline ll rd()
{
	ll x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

inline void print(ll x)
{
	static char s[233];
	if (!x) { putchar('0');putchar('\n');return; }
	int tot=0;
	for (;x;x/=10) s[++tot]=x%10+'0';
	for (;tot;tot--) putchar(s[tot]);
	putchar('\n');
}

inline void gao(ll x,ll y)
{
	if (!mp.count(x)) mp[x]=y;
	else mp[x]=min(mp[x],y);
}

inline void work()
{
	n=rd();a=rd();b=rd();c=rd();d=rd();
	mp.clear();mp[n]=0;
	ll ans=inf;
	while (233)
	{
		map<ll,ll>::iterator it=mp.end();it--;
		ll x=it->first,y=it->second;
		ans=min(ans,y+x*d);
		if (!x) break;
		if (x%2==0) gao(x/2,y+a);
		else gao(x/2,y+a+d),gao(x/2+1,y+a+d);
		if (x%3==0) gao(x/3,y+b);
		else gao(x/3,y+b+x%3*d),gao(x/3+1,y+b+(3-x%3)*d);
		if (x%5==0) gao(x/5,y+c);
		else gao(x/5,y+c+x%5*d),gao(x/5+1,y+c+(5-x%5)*d);
		mp.erase(mp.find(x));
	}
	print(ans);
}

int main()
{
	t=rd();
	while (t--) work();
	return 0;
}

Measured memory_bytes: 3656
var lines = [];
var readline = require('readline');
 
var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});
 
rl.on('line', function (x) {
    lines.push(x);
});
 
rl.on('close', function () {
    var A = Number(lines[0].split(" ")[0]);
    var B = Number(lines[0].split(" ")[1]);
    var C = Number(lines[0].split(" ")[2]);
 
    if (A === B && A === C && B === C) { console.log("Yes") }
    else { console.log("No") }
});

Measured memory_bytes: 21320