akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
typedef long long ll;
const ll MOD=1e+9+7;
struct mint{
  ll x;
  mint(ll x=0):x(x%MOD){}
  mint& operator+=(const mint a){
    if((x+=a.x)>=MOD) x-=MOD;
    return *this;
  }
  mint& operator-=(const mint a){
    if((x += MOD-a.x)>=MOD) x-=MOD;
    return *this;
  }
  mint& operator*=(const mint a){
    (x*=a.x)%=MOD;
    return *this;
  }
  mint operator+(const mint a) const{
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const{
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const{
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const{
    if(!t) return 1;
    mint a = pow(t>>1);
    a*=a;
    if(t&1) a*=*this;
    return a;
  }
  
  //for prime mod
  mint inv() const{
    return pow(MOD-2);
  }
  mint& operator/=(const mint a){
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const{
    mint res(*this);
    return res/=a;
  }
};

const int NMAX=200010; // we can calculate nCk until n is equal to NMAX
mint fact[NMAX],infac[NMAX];
void Make_Fact(){
  fact[0]=fact[1]=1;
  for(int i=2;i<=NMAX-1;++i){
    fact[i]=fact[i-1]*(mint)i;
  }
}
void Make_InvFact(){
  infac[0]=infac[1]=1;
  for(int i=2;i<=NMAX-1;++i){
    infac[i]=infac[i-1]/(mint)i;
  }
}
mint Comb(int n,int k){
  if(n<0||k<0||n-k<0) return 0;
  return fact[n]*infac[k]*infac[n-k];
}

int main()
{
  int n,m,k;cin >> n >> m >> k;
  Make_Fact();
  Make_InvFact();
  mint res;
  rep1(i,n) {
    rep1(j,m) {
      mint tmp = (Comb(i, 2) + Comb(n - i + 1, 2)) * (mint)m + (Comb(j, 2) + Comb(m - j + 1, 2)) * (mint)n;
      tmp *= Comb(n*m - 2, k - 2);
      res += tmp;
    }
  }
  res /= 2;
  cout << res.x << "\n";
  
  return 0;
}


Measured memory_bytes: 3328
#include <stdio.h>
#define N 20
#define Q 200
int n, A1[N], flg;

void solve(int p, int q){
  if(q > 0 && flg == 0 && p < n){
    if( q == A1[p]){
      flg = 1;
      printf("yes\n");
      return;
    }
    solve(p+1, q-A1[p]);
    solve(p+1, q);
  }
}

main(){
  int i;
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d", &A1[i]);
  }

  int q, A2[Q];
  scanf("%d", &q);
  for(i = 0; i < q; i++){
    scanf("%d", &A2[i]);
    flg = 0;
    solve(0, A2[i]);
    if(flg == 0){
      printf("no\n");
    }
  }
  return 0;
}

Measured memory_bytes: 580
import numpy as np
n,W=map(int,input().split())
wv=[list(map(int,input().split())) for i in range(n)]
wv=np.array(wv)
dp=[0]*(W+1)
dp=np.array(dp)
for w,v in wv:
  dp[w:]=np.maximum(dp[w:],dp[:-w]+v)
print(dp[W])

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

int main () {

	ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);

		int N; cin >> N;
		vector<vector<int>> a(N, vector<int>(2));
		for (int i = 0; i < N; ++i)
			for (int j = 0; j < 2; ++j)
				cin >> a[i][j];
		for (int i = 0; i < N-2; ++i) {
			if (a[i][0] == a[i][1] && a[i+1][0] == a[i+1][1] && a[i+2][0] == a[i+2][1]) {
				cout << "Yes" << '\n'; return 0;
			}
		}
		cout << "No" << '\n';

	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<long long> vec(N);
  for (int i = 0; i < N; i++) cin >> vec.at(i);
  
  int zero = 0;
  for (int i = 0; i < N; i++) if(vec.at(i) == 0) zero++;
  if (zero > 0) {
    cout << '0';
    return 0;
  }
  
  long long prod = 1;
  for (int i = 0; i < N; i++) {
    if (vec.at(i) > 1000000000000000000 / prod) {
      cout << "-1";
      return 0;
    } else {
      prod *= vec.at(i);
    }
  }
  cout << prod;
}


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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }
const ll MOD = 1e9+7;
#define pii pair<int,int>
#define pll pair<ll,ll>

int main(){
    ll S; cin>>S; // abs(x1y2-x2y1)=S
    ll x1 = sqrt(S)+1;
    if(x1>pow(10,9)){ x1 = pow(10,9); }
    ll y1 = x1*x1-S;
    ll x2 = 1;
    ll y2 = x1;
    ll x3 = 0;
    ll y3 = 0;
    printf("%Ld %Ld %Ld %Ld %Ld %Ld\n",x1,y1,x2,y2,x3,y3);
    
}

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

using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;i++)

int main(){
	ll N; cin>>N;
	vector<ll>A(N+1);
	vector<ll>d(N);
	ll sum=0;
	rep(i,N){
		cin>>A[i];
		sum+=A[i];
	}
	A[N]=A[0];

	if(sum%((N+1)*N/2)==0){
		ll K=sum/((N+1)*N/2);//操作回数
		rep(i,N){
			d[i]=A[i+1]-A[i];
			d[i]-=K;
		}
		//{d}のうちひとつを+(N-1),その他-1する
		// =すべて-1,1つ+N
		//K回で0にできるか

		//-Kと(+N)*K
		rep(i,N){
			if(d[i]>0 || (-d[i])%N!=0){
				cout<<"NO";
				return 0;
			}
		}
		cout<<"YES";
	}
	else{
		cout<<"NO";
	}

}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define loop(i,n) rep(i,0,n)
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    multiset<int> st;
    loop(i,n){
        int a;
        cin >> a;
        auto itr=st.lower_bound(a);
        if(!st.empty() && itr!=st.begin()){
            --itr;
            st.erase(itr);
        }
        st.emplace(a);
    }
    cout << st.size() << endl;
    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  ll A,B,C;
  cin>>A>>B>>C;
  if(A+B<C) {
cout<<"No"<<endl;
  }
  
  else {
cout<<"Yes"<<endl;
  }
}

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

#define REP(var,start,end) for(int var=start; var<end; var++)

int main(void) {
	
	unsigned int N, K;
	cin >> N >> K;
	
	unsigned int kouho[32];
	long long sum[32];
	kouho[0] = K;
	sum[0] = 0;
	REP(z, 1, 32) {
		kouho[z] = 0;
		sum[z] = 0;
		if ( K & (1<<z) ) {
			unsigned int mask = (1<<z)-1;
			kouho[z] = (K & (~(1<<z))) | mask;
		}
	}
	
	REP(i, 0, N) {
		int A, B;
		cin >> A >> B;
		
		REP(z, 0, 32) {
			if ( (A & ~kouho[z]) == 0 ) {
				sum[z] += B;
			}
		}
	}
	
	long long ret = 0;
	REP(z, 0, 32) {
		if ( sum[z] > ret ) { ret = sum[z]; }
	}
	
	cout << ret <<endl;
	
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    lint n, k;
    cin >> n >> k;
    
    vector<lint> pos, neg;
    pos.push_back(0);
    neg.push_back(0);
    rep (n) {
        lint a;
        cin >> a;
        if (a < 0) neg.push_back(-a);
        else if (a > 0) pos.push_back(a);
        else --k;
    }
    
    sort(neg.begin(), neg.end());
    sort(pos.begin(), pos.end());
    
    lint ps = pos.size();
    lint ns = neg.size();
    
    lint ans = 1e18;
    repeat (i, ns) {
        if (i > k) continue;
        if (k-i >= ps) continue;
        ans = min(ans, neg[i]*2 + pos[k-i]);
        //dump(i); dump(neg[i]); dump(pos[k-i]); dump(ans); el;
    }
    repeat (i, ps) {
        if (i > k) continue;
        if (k-i >= ns) continue;
        ans = min(ans, pos[i]*2 + neg[k-i]);
        //dump(i); dump(pos[i]); dump(neg[k-i]); dump(ans); el;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1656
#include <stdio.h>
#include <math.h>
#define DIST( x1, y1, x2, y2) sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))
#define myround(r, keta) (round(r*pow(10,keta))/pow(10,keta))
int main(){
	int n;
	int i;
	double x1,y1,x2,y2,x3,y3;
	double a,b,c;
	double s,r;
	double A,B,C;
	double px,py;
	scanf("%d",&n);
	for(i = 0;i < n;i++){
		scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3);
		a = DIST(x2, y2, x3, y3);
		b = DIST(x1, y1, x3, y3);
		c = DIST(x1, y1, x2, y2);
		A = a*a;
		B = b*b;
		C = c*c;
		s = sqrt(2*(A*B+A*C+B*C)-(A*A+B*B+C*C))/4;
		r = a*b*c/4/s;
		px = (A*(B+C-A)*x1+B*(C+A-B)*x2+C*(A+B-C)*x3)/16/s/s;
		py = (A*(B+C-A)*y1+B*(C+A-B)*y2+C*(A+B-C)*y3)/16/s/s;

		printf("%.3lf %.3lf %.3lf\n", myround(px,3),myround(py,3),myround(r,3));
	}
	return 0;
}

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

int main()
{
    string s;
    while(cin>>s)
    {
        if(s.length()==6&&s[2]==s[3]&&s[4]==s[5])
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 256
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, k = list(map(int, input().rstrip('\n').split()))
    s = str(input().rstrip('\n'))
    cnt = 0
    for i in range(1, n):
        if s[i] == s[i-1]:
            cnt += 1
    print(min(n - 1, cnt + k * 2))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 39536
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;

template<typename T>void chmax(T &a,T b){a=max(a,b);}
template<typename T>void chmin(T &a,T b){a=min(a,b);}
using namespace std;

void solve(){
	int n;
	cin>>n;
	vector<ll>a(n);
	ll ans=0,minv=1e9+5;
	rep(i,n){
		cin>>a[i];
	}
	sort(begin(a),end(a));
	rep(i,n){
		rep(j,a[i]%2)ans^=(n-i);
	}
	if(ans!=0)cout<<"first\n";
	else cout<<"second\n";
}

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


Measured memory_bytes: 1024
n=int(input())
s=list(input())
b2=s.count("#")
w2=s.count(".")
b1=0
w1=0
ans=w2
for i in range(n):
    if s[i]=="#":
        b1+=1
        b2-=1
    else:
        w1+=1
        w2-=1
    ans=min(ans,b1+w2)
print(ans)


Measured memory_bytes: 10784
import math

def ans(n):
  diff = abs(math.radians(6)*n[3] - (math.radians(30)*n[2] + math.radians(0.5)*n[3]))
  if diff < math.radians(180):
    print(math.sqrt(n[0]**2 + n[1]**2 -2*n[0]*n[1]*(math.cos(diff))))
  elif diff > math.radians(180): 
    print(math.sqrt(n[0]**2 + n[1]**2 -2*n[0]*n[1]*(math.cos(math.radians(360) - diff))))
  else:
    print(n[0] + n[1])

ans(list(map(int,input().split())))


Measured memory_bytes: 9580
num = int(input())
sort_list = list(map(int,input().split()))

for i in range(1,num):
    for n, sl in enumerate(sort_list):
        if n != num - 1:
            print('{} '.format(sl),end='')
        else:
            print('{}'.format(sl))

    tmp = sort_list[i]
    j = i -1
    while j >= 0 and sort_list[j] >= tmp:
        buf = sort_list[j]
        del sort_list[j]
        sort_list.insert(j + 1, buf)
        j -= 1

for n, sl in enumerate(sort_list):
    if n != num - 1:
        print('{} '.format(sl),end='')
    else:
        print('{}'.format(sl))



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

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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void vprint(vector<ll> A){
    ll L = A.size();
    FOR(i, 0, L){
        if(i) cout << ' ';
        cout << A[i];
    }
    cout << endl;
}

const int W_MAX = 2010;
ll U[2010][2010];
ll D[2010][2010];
ll L[2010][2010];
ll R[2010][2010];

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

    // input
    ll H, W;
    cin >> H >> W;

    vector<string> S(H);
    FOR(i, 0, H){
        cin >> S.at(i);
    }

    // 左への光線
    FOR(y, 0, H){
        ll x = -1;
        FOR(i, 0, W){
            if(S[y][i]=='#'){
                x = i;
                L[y][i] = -1;
            }else{
                L[y][i] = x;
            }
        }
    }

    // FOR(i, 0, 10){
    //     cout << L[0][i] << ' ';
    // }
    // cout << endl;

    // Right
    FOR(y, 0, H){
        ll x = W;
        for(int i=W-1; i>=0; i--){
            if(S[y][i]=='#'){
                x = i;
                R[y][i] = -1;
            }else{
                R[y][i] = x;
            }
        }
    }

    // FOR(i, 0, 10){
    //     cout << R[0][i] << ' ';
    // }
    // cout << endl;

    // UP
    FOR(x, 0, W){
        ll y = -1;
        FOR(i, 0, H){
            if(S[i][x]=='#'){
                y = i;
                U[i][x] = -1;
            }else{
                U[i][x] = y;
            }
        }
    }

    // FOR(i, 0, 10){
    //     cout << U[i][4] << endl;
    // }

    // Down
    FOR(x, 0, W){
        ll y = H;
        for(int i=H-1; i>=0; i--){
            if(S[i][x]=='#'){
                y = i;
                D[i][x] = -1;
            }else{
                D[i][x] = y;
            }
        }
    }

    // FOR(i, 0, 10){
    //     cout << D[i][0] << endl;
    // }

    ll ma = 0;
    FOR(y, 0, H){
        FOR(x, 0, W){
            if(S[y][x]=='#') continue;

            ll light = 1;
            light += (x - L[y][x] - 1);
            light += (R[y][x] - x - 1);

            light += (y - U[y][x] - 1);
            light += (D[y][x] - y - 1);

            chmax(ma, light);
        }
    }
    p(ma);
    
    return 0;
}

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

int main(){
  string s;
  cin >>s;
  int st =-1,la=-1;
  for(int i=0;i<s.size();i++){
    if (st<0 && s.at(i)=='A'){
      st =i;
    }
    if(st >=0 && s.at(i)=='Z'){
      la =i;
    }
  }
  cout <<la-st+1<<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
char buf[1<<20],*p1,*p2;
#define GC (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?0:*p1++)
template<class T> inline void read(T &n){
	char ch=GC;T w=1,x=0;
	while(!isdigit(ch)){if(ch=='-') w=-1;ch=GC;}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=GC;}
	n=x*w;
}
int n,A,B,N;
int cnt[1<<17];
#define vec vector <int> 
vec solve(int nw,int st,int ed){
	vec res;
	res.resize(1<<nw);
	if(nw==1){
		res[0]=st,res[1]=ed;
		return res;
	}
	int pos=0;
	for(int i=0;i<nw;i++)
		if((st&(1<<i))!=(ed&(1<<i))){
			pos=i;break;
		}
	int nxts=((st>>(pos+1))<<pos)|(st&((1<<pos)-1));
	int nxte=((ed>>(pos+1))<<pos)|(ed&((1<<pos)-1));
	vec L=solve(nw-1,nxts,cnt[nxts]^1),R=solve(nw-1,cnt[nxts]^1,nxte);
	int S=(1<<(nw-1));
	for(int i=0;i<S;i++){
		res[i]=((L[i]>>pos)<<(pos+1))|(L[i]&((1<<pos)-1));
		res[i]|=(st&(1<<pos));
	} 
	for(int i=0;i<S;i++){
		res[i+S]=((R[i]>>pos)<<(pos+1))|(R[i]&((1<<pos)-1));
		res[i+S]|=(ed&(1<<pos));
	} 
	return res;
}
int main(){
	read(n),read(A),read(B);
	for(int i=0;i<(1<<n);i++) cnt[i]=(cnt[i>>1]^(i&1));
	if(!cnt[A^B]) puts("NO"),exit(0);
	vec ans=solve(n,A,B);
	puts("YES");
	for(int i=0;i<(1<<n);i++) printf("%d ",ans[i]);
	return 0;
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back

int main(){
    string S;
    cin >> S;
    string AD = "";
    for(int i = 0; i < S.size() - 1;){
        if(S.substr(i, 2) == "BC"){
            AD += 'D';
            i += 2;
        } else {
            AD += S[i];
            i++;
        }
    }
    i64 ans = 0, A = 0;
    for(int i = 0; i < AD.size(); i++){
        if(AD[i] == 'A') A++;
        else if(AD[i] == 'D') ans += A;
        else A = 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 900
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

Int f(Int a, Int b, Int x) {
    Int ret = a * x / b - a * (x / b);
    return ret;
}

int main() {
    Int a, b, n;
    cin >> a >> b >> n;
    Int ans = f(a, b, min(b-1, n));
    cout << ans << endl;
}

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

#define forn(i,n) for(int i=0;i<n;i++)
#define pb push_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
int ma=400;
ll dp[400][400];
ll INF=1e18;
ll sum(int l,int r,vector<int>&v){
    ll g=0;
    for(int i=l;i<=r;i++)g+=v[i];
    return g;
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);	
        int n;cin>>n;
        vector<int>v(n);
        forn(i,n)cin>>v[i];
        for(int l=n-2;l>=0;l--){
            for(int r=l+1;r<=n-1;r++){
                ll x=sum(l,r,v);
                dp[l][r]=INF;
                for(int i=l;i<=r-1;i++){
                    dp[l][r]=min(dp[l][r],dp[l][i]+dp[i+1][r]+x);
                }
            }
        }
        //for(int i=0;i<=n;i++){
            //for(int j=0;j<=n;j++){
                //cout<<dp[i][j]<<" ";
            //}
            //cout<<endl;
        //}
        cout<<dp[0][n-1]<<endl;
}


Measured memory_bytes: 1536
#include<stdio.h>
#include<string.h>
 
void print(char str[1000], int a, int b) {
    char substr[1000];
    strncpy(substr, str + a, b - a + 1);
    substr[b - a + 1] = '\0';
    printf("%s\n", substr);
}
 
void reverse(char str[1000], int a, int b) {
    int i;
    char revstr[1000];
    strcpy(revstr, str);
    for (i = a;i <= b;i++) {
        revstr[i] = str[b + a - i];
    }
    strcpy(str, revstr);
}
 
void replace(char str[1000], int a, int b, char p[1000]) {
    int i;
    for (i = a;i <= b;i++) {
        str[i] = p[i - a];
    }
}
 
int main() {
    int i;
    int a, b, n;
    char str[1000], p[1000];
    char op[10];
     
    scanf("%s", str);
    scanf("%d", &n);
 
    for (i = 0;i < n;i++) {
        scanf("%s", op);
 
        if (strcmp(op, "print") == 0) {
            scanf("%d %d", &a, &b);
            print(str, a, b);
        }
        else if (strcmp(op, "reverse") == 0) {
            scanf("%d %d", &a, &b);
            reverse(str, a, b);
        }
        else if (strcmp(op, "replace") == 0) {
            scanf("%d %d %s", &a, &b, p);
            replace(str, a, b, p);
        }
    }
 
    return 0;
}

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

int main(){

	  int a,b,c ;
	  cin >> a >> b >> c;

	  if( c % (a+b) <= a ){
			cout << c << endl;
			return 0;
	  }else{

			if( 60%(a+b) == 0 ) {
			L1:
				  cout << -1 << endl;
				  return 0;
			}
			else{
				  int x=c;
				  int t=0;
				  set<int> s;
				  while( c % (a+b) > a ) {
						c = c%(a+b);
						c += 60; t++;
						if( s.count(c) != 0)goto L1;
						s.insert(c);
				  }
				  cout << x+(60*t) << endl;
				  return 0;
			}
	  }

}

Measured memory_bytes: 1196
#include <stdio.h>
int main(void)
{
	int i, c;
	char s[20];
	scanf("%s", s);
	for (i = 0; s[i] != '\0'; i++) {
		if (s[i] == 'x') {
			c = c + 1;
		}
	}
	if (c < 8) {
		printf("YES");
	}
	else {
		printf("NO");
	}

	return 0;
}

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

int main()
{
    string S;
    cin >> S;
    bool can = true;
    rep(i,S.size()){
        if(S.substr(i,2) != "hi"){
            can = false;
            break;
        }
        i++;
    }
    if(can) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int a[114];int n,cnt=0;
signed main(){
	cin>>n;
	rep(i,n)cin>>a[i];
	sort(a,a+n);
	rep(i,n){
		if(a[i]==a[i+1])cnt++;
	}
	cout<<n-cnt<<endl;
}
		
		


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    
    int v = min(b, d) - max(a, c);
    put(max(0, v))

    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>


typedef long long ll;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBAC
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/
//copy(v1.begin(), v1.end(), back_inserter(v2));
using namespace std;

int gcd(int a, int b) {
	int c;
	if (a < b) {
		c = a; a = b; b = c;
	}
	while (b != 0) {
		c = a % b; a = b; b = c;
	}
	return a;
}

int sort_greater(int m,int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(),greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
		return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

int a_z()
{
	for (int i = 0; i <= ('Z' - 'A'); i++) {
		cout << (char)('A' + i);
	}
	return 0;
}

int selecttionsort(int a[], int n) {
	int t,sw = 0, minj;
	for (int i = 0; i < n - 1; i++) {
		minj = i;
		for (int j = 0; j < n - 1; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		t = a[i]; a[i] = a[minj]; a[minj] = t;
		if (i != minj) sw += 1;

	}
	return sw;
}

bool is_prime(int x) {
	if (x <= 1) return false;
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0) return false;
	}
	return true;
}

map<string, int> memo;

using P=pair<int, int>;

struct Clock {
	int hour, minute, second;
	void set(int h, int m, int s) {
		hour = h; minute = m; second = s;
	}
	string to_str() {
		string h, m, s;
		h = to_string(hour);
		m= to_string(minute);
		s= to_string(second);
		if (h.size() < 2) h = "0" + h;
		if (m.size() < 2) m = "0" + m;
		if (s.size() < 2) s = "0" + s;
		return h + ":" + m + ":" + s;
	}
	void shift(int diff_second) {
		int h, m;
		h = diff_second / 3600;
		m = diff_second / 60;
		diff_second %= 60;
		second += diff_second;
		
	}
};


/*void dfs(int v, int p = -1) {
	for (int u : to[v]) {
		if (u == p) continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}*/
int main() {
	//sort(a.begin(),a.end());
	int n;
	cin >> n;
	vector<string> s(n);
	rep(i, n) { cin >> s[i]; sort(s[i].begin(), s[i].end()); }
	ll ans = 0,a=1;
	sort(s.begin(), s.end());
	rep(i, n - 1) {
		if (s[i] == s[i + 1]) {
			ans += a;
			a++;
		}
		else {
			a = 1;
		}
		
	}
	cout << ans;
	return 0;
}









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

int maxhap(int ar[][3],int n)
{
    int hap[n][3];// oi position er element ta k include korle highest koto happiness gain hoy

    for(int i=0; i<3; i++){
        hap[n-1][i]=ar[n-1][i];
    }

    for(int i=n-2; i>=0; i--){
        int a,b;

        a=hap[i+1][1];
        b=hap[i+1][2];
        hap[i][0]=ar[i][0]+max(a,b);

        a=hap[i+1][0];
        b=hap[i+1][2];
        hap[i][1]=ar[i][1]+max(a,b);

        a=hap[i+1][0];
        b=hap[i+1][1];
        hap[i][2]=ar[i][2]+max(a,b);

    }

    int a=hap[0][0];
    int b=hap[0][1];
    int c=hap[0][2];

    if(a>=b && a>=c){
        return a;
    }
    else if(b>=a && b>=c){
        return  b;
    }

    else if(c>=a && c>=b){
        return c;
    }

}

int main()
{
    int n;
    cin>>n;
    int ar[n][3];
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            cin>>ar[i][j];
        }
    }

    cout << maxhap(ar,n);
}






Measured memory_bytes: 2560
#!/usr/bin/env python3

def main():
    n, t = map(int, input().split())
    an = list(map(int, input().split()))

    mi = [an[0]]
    for i in range(1, n):
        mi.append(min(mi[i - 1], an[i]))

    ma = 0
    num_ma = 0
    for i in range(1, n):
        be = an[i] - mi[i - 1]
        if be > ma:
            ma = be
            num_ma = 1
        elif be == ma:
            num_ma += 1
    print(num_ma)

main()


Measured memory_bytes: 14292
#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 1e5
#define INF 1<<30
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;


int main() {
	cin >> A >> P;
	cout << (3 * A + P) / 2 << endl;
	
}


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

#pragma GCC optimize "trapv"
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,a,b) for(int i=a; i<b; i++)
#define drep(i,a,b) for(int i=a; i>b; i--)
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define ll long long
#define inf 1e+18L
#define mod 1000000007

const auto pi = 3.14159265358979;

template <typename T>
T numdigits(T n)
{
    return (floor(log10(n)) + 1);
}

template <typename T>
T modpower(T x, T y, T m=mod)
{
    T res = 1;
    x %= m;
    if(x == 0) return 0;
    while(y > 0)
    {
        if(y&1) res = (res*x)%m;
        y >>= 1;
        x = (x*x)%m;
    }
    return res;
}

void solve()
{
    //code
    int r;
    cin >> r;
    cout << fixed << setprecision(10) << 2*pi*r << "\n";
}

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

Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
#define int                     long long   
#define double                  long double
#define endl                    "\n"
#define pb                      push_back
#define PI                      3.1415926535897932384626433832795l
#define F                       first
#define S                       second
#define mp                      make_pair
#define f(i,n)                  for(int i=0;i<n;i++)
#define fastio                  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v)                  (v).begin(),(v).end()
#define rall(v)                 (v).rbegin(),(v).rend()
#define gcd(a,b)                __gcd((a),(b))
#define fill(a,value)           memset(a,value,sizeof(a));
#define minn(v)                 *min_element(v.begin(), v.end());
#define maxx(v)                 *max_element(v.begin(), v.end());
#define print(x)                cout<<(x)<<endl;
#define sum(v)+x                accumulate(v.begin(), v.end(),x);
#define debug(x)                cout<<#x<<'='<<(x)<<endl;
typedef pair<int,int>           pii;
typedef vector<int>             vi;
 
int dig(int x)
{
    int ans=0;
    while(x>0)
    {
        ans++;
        x/=10;
    }
    return ans;
}
signed main() 
{
    fastio;
    cout << fixed << setprecision(12);
    int n;
    cin>>n;
    int t=dig(n);
    int ans=0;
    for(int i=1;i<t;i+=2)
    {
        ans+=9*(pow(10,i-1));
    }
    if(t%2)
    {
        ans+=n-(int)(pow(10,t-1))+1;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4116
#include <bits/stdc++.h> 
 
#define INF (1<<31)//INT_MAX/2
#define MOD 1000000007
 
using ll  = long long;
using ull = unsigned long long;
 
int main(int argc, char *argv[])
{
    int N;
    std::cin >> N;

    if (N != 1) {
        std::map<int, int> m;

        for (int i = 1; i <= N; i++) {
            int num = i;
            int count = 0;
            while (num % 2 == 0) {
                num /= 2;
                count++;
            }
            m[i] = count;
        }

        int max = 0;
        int num = 0;
        std::map<int, int>::iterator it;

        for (it = m.begin(); it != m.end(); it++) {
            if (max < it->second) {
                max = it->second;
                num = it->first;
            }
        }

        std::cout << num << std::endl;
    } else {
        std::cout << 1 << std::endl;
    }

    return 0;
}

Measured memory_bytes: 256
// g++ -std=gnu++1y -O2 xxx.cpp

#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 A,B,M; cin>>A>>B>>M;
       
    vector<int> a(A),b(B);
    rep(i,A) cin>>a[i];
    rep(i,B) cin>>b[i];

    int minTotal=INT_MAX;
    rep(i,M) {
        int x,y,c; cin>>x>>y>>c;
        int sum=a[x-1]+b[y-1]-c;
        minTotal = min(minTotal,sum);
    }

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

    cout << min({a[0]+b[0],minTotal}) << endl;

    return 0;
}

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

typedef long long ll;

const int maxn = 1e5+10;

int cor[maxn][14], qwq[maxn], qaq[maxn], c[maxn];

std::vector <int> pb[maxn];

int n, m, a, b, q;

void paint(int v1, int d1, int c1)
{
    if(d1==-1)  return;
    if(cor[v1][d1] ) return;
    cor[v1][d1] = c1;
    for(int i =0;i<pb[v1].size();i++)
        paint(pb[v1][i], d1-1, c1);
}

int read()
{
	int x=0, ch= getchar(), f=1;
	while(!isdigit(ch)){ if(ch == '-')f = -1, ch = getchar();}
	while(isdigit(ch)) x = x *10 + ch-'0', ch = getchar();
	return x * f;
} 

int main()
{
    n=read(), m=read();
    for(int i=1;i<=m;i++) a=read(), b=read(), pb[a].push_back(b), pb[b].push_back(a);
    for(int i=1;i<=n;i++) pb[i].push_back(i);
    q=read();
    for(int i=1;i<=q;i++) qwq[i]=read(), qaq[i] = read(), c[i] = read();
    for(int i=q;i>=1;i--)  paint(qwq[i], qaq[i], c[i]);
    for(int i=1;i<=n;i++) std::cout<<cor[i][0]<<std::endl;
    return 0;
}

Measured memory_bytes: 13176
import sys


def main():
    a, b = map(int, input().split())

    if a == b:
        print("Draw")
    elif (a > b and b != 1) or a == 1:
        print("Alice")
    elif (b > a and a != 1) or b == 1:
        print("Bob")
    else:
        print("You must be wrong ...")
        sys.exit()


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    int K = scanner.nextInt();
    int[] a = new int[N + 1];
    for (int i = 1; i <= N; i++) a[i] = scanner.nextInt();

    boolean[][] dp1 = new boolean[N + 1][K + 1];
    for (int i = 0; i <= N; i++) dp1[i][0] = true;
    for (int i = 1; i <= N; i++) {
      for (int j = 1; j <= K; j++) {
        dp1[i][j] = dp1[i - 1][j] || (j >= a[i] && dp1[i - 1][j - a[i]]);
      }
    }

    boolean[][] dp2 = new boolean[N + 1][K + 1];
    for (int i = 0; i <= N; i++) dp2[i][0] = true;
    for (int i = N - 1; i >= 0; i--) {
      for (int j = 1; j <= K; j++) {
        dp2[i][j] = dp2[i + 1][j] || (j >= a[i + 1] && dp2[i + 1][j - a[i + 1]]);
      }
    }

    int count = 0;
    loop:
    for (int i = 1; i <= N; i++) {
      int rc = 0;
      for (int j = 0; j <= K; j++) if (dp2[i][j]) rc++;
      int[] right = new int[rc];
      int idx = 0;
      for (int j = 0; j <= K; j++) if (dp2[i][j]) right[idx++] = j;

      int min = Math.max(0, K - a[i]);
      for (int j = 0; j <= K; j++) {
        if (dp1[i - 1][j]) {
          int r = findLowerBound(right, Math.max(0, min - j));
          if (r >= 0 && j + r < K) {
            count++;
            continue loop;
          }
        }
      }
    }
    System.out.println(N - count);
  }

  private static int findLowerBound(int[] list, int min) {
    int left = -1;
    int right = list.length;
    while (right - left > 1) {
      int mid = (left + right) / 2;
      if (list[mid] >= min) {
        right = mid;
      } else {
        left = mid;
      }
    }
    return right == list.length ? - 1 : list[right];
  }
}


Measured memory_bytes: 139640
#include<iostream>
#include<string>
using namespace std;
int main() {
	bool a[10001];
	fill(a, a + 10001, true);
	a[0] = false; a[1] = false;
	for (int i = 2; i <= 10000; i++) {
		if (a[i]) {
			int j = 2;
			while (i*j <= 10000) {
				a[i*j] = false;
				j++;
			}
		}
	}
	int b;
	while (cin >> b&&b!=0) {
		for (int i = b; i >= 2; i--) {
			if (a[i] && a[i - 2]) {
				cout << i - 2 << " " << i << endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 3096
import java.util.Arrays;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    // TODO 自動生成されたメソッド・スタブ
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();

    int k = sc.nextInt();
    int[] h = new int[100200];
    for (int i = 0; i < n; i++) {
      h[i] = sc.nextInt();
    }

    int dp[] = new int[100200];
    Arrays.fill(dp, Integer.MAX_VALUE);

    dp[0] = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 1; j <= k; j++) {
        dp[i + j] = Math.min(dp[i + j], dp[i] + Math.abs(h[i] - h[i + j]));
      }
    }
    System.out.println(dp[n - 1]);
  }
}


Measured memory_bytes: 49520
#include <bits/stdc++.h>
using namespace std;
using PP = pair<int, int>;

const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };
const int inf = 1e9;

int h, w;
string s[1000];
int dist[1000][1000];
int main() {
  cin >> h >> w;
  for (int i = 0; i < h; ++i) {
    cin >> s[i];
  }
  
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      dist[i][j] = inf;
    }
  }
  
  queue<pair<int, PP>> q;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (s[i][j] == '#') {
        q.push(make_pair(0, PP(i, j)));
      }
    }
  }
  
  int mx = 0;
  while (!q.empty()) {
    auto p = q.front(); q.pop();
    int d = p.first;
    int i = p.second.first;
    int j = p.second.second;
    
    if (i < 0 || i >= h) continue;
    if (j < 0 || j >= w) continue;
    if (dist[i][j] != inf) continue;
    dist[i][j] = d;
    mx = d;
    
    for (int k = 0; k < 4; ++k) {
      int ni = i + di[k];
      int nj = j + dj[k];
      q.push(make_pair(d + 1, PP(ni, nj))); 
    }
  }
  cout << mx << endl;
}

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

const string T = "CODEFESTIVAL2016";

int main(){
    string S;
    cin >> S;
    int ans = 0;
    for (int i = 0; i < S.length(); i++) {
        if (S[i] != T[i]) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
import math
import bisect

def main():
    a = int(input())
    b = int(input())
    c = int(input())
    x = int(input())
    x //= 50
    dp = [0] * (x + 1)
    dp[0] = 1
    for i in range(x, -1, -1):
        for j in range(1, a + 1):
            if i - 10 * j >= 0:
                dp[i] += dp[i-10*j]
    for i in range(x, -1, -1):
        for j in range(1, b + 1):
            if i - 2 * j >= 0:
                dp[i] += dp[i-2*j]
    for i in range(x, -1, -1):
        for j in range(1, c + 1):
            if i - j >= 0:
                dp[i] += dp[i-j]
    print(dp[x])

if __name__ == "__main__":
    main()


Measured memory_bytes: 40432
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import deque
import pprint

inf = 10**18
mod = 10**9+7

n,k = map(int, input().split())
b = list(map(int, input().split()))
a = [0]
for i in b:
    a.append(i)

flag = False
while k > 0 and (not flag):
    flag = True
    a2 = [0 for i in range(n+1)]
    for i,num in enumerate(a[1:]):
        l = max(i-num,0)
        r = min(i+num,n-1)
        l+=1
        r+=1
        a2[l] += 1
        if r+1 != n+1:
            a2[r+1] -= 1

    a = [0 for i in range(n+1)]
    for i in range(1, n+1):
        a[i] += a[i-1] + a2[i]
        if a[i] != n:
            flag=False
    k-=1
if flag:
    print(*[n for i in range(n)], sep=' ')
else:
    print(*a[1:], sep=' ')

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

int main(){

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

    int n;
    cin >> n;
    vector<pair<int,int>> v(n);
    for(int i=0; i<n; i++){
        cin >> v[i].first >> v[i].second;
    }

    bool flag=true;
    for(int i=0; i<=n-3; i++){
        flag=true;
        for(int j=0; j<3; j++){
            if(v[i+j].first != v[i+j].second){
                flag=false;break;
            }
        }
        if(flag) break;
    }

    if(flag){
        cout<<"Yes\n";
    }else{
        cout<<"No\n";
    }

    return 0;
}


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

#define rep(i,n) for(ll i = 0; i < (n); i++)
#define repd(i,n) for(ll i = (n); i >= 0; i--)
#define FOR(i,t,n) for(ll i = (t); i < (n); i++)
#define FORD(i,t,n) for(ll i = (n); i >= t; i--)
#define ALL(x) x.begin(),x.end()
#define asort(x) sort(ALL(x))

int main() {
    ll N, res = 0;
    cin >> N;
    vector<ll> L(N);
    rep(i,N) cin >> L[i];
    rep(i,N) {
        FOR(j,i+1,N) {
            if(L[i] == L[j]) continue;
            FOR(k,j+1,N) {
                if(L[i] == L[k] || L[j] == L[k]) continue;
                if(L[i] + L[j] > L[k] && L[j] + L[k] > L[i] && L[i] + L[k] > L[j]) {
                    res++;
                }
            }
        }
    }
    cout << res << endl;
}

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

int main(){
    ll n,m;
    cin >> n >> m;
    vector<vector<ll>> links(n);
    for(ll i=0;i<m;i++){
        ll a,b;
        cin >> a >> b;
        links[a-1].push_back(b-1);
        links[b-1].push_back(a-1);
    }

    vector<ll> signs(n);
    for(ll i=0;i<n;i++){
        signs[i]=-1;
    }
    signs[0]=-2;

    queue<ll> squeue;
    squeue.push(0);

    while(squeue.size()>0){
        ll now= squeue.front();
        squeue.pop();
        for(ll i=0;i<links[now].size();i++){
            if(signs[links[now][i]]==-1){
                signs[links[now][i]]=now;
                squeue.push(links[now][i]);
            }
        }
    }
    for(ll i=0;i<n;i++){
        if(signs[i]==-1){
            cout << "No";
            return 0;
        }
    }
    cout << "Yes" <<"\n";
    for(ll i=1;i<n;i++){
        cout << signs[i]+1 <<"\n";
    }
    return 0;
}


Measured memory_bytes: 12976
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <climits>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,int> pli;
typedef pair<long long, long long> pll;

int dp[100005];
int six[9];
int nine[9];

int dfs(int n) {
  if(dp[n] != -1) return dp[n];
  if(n < 5) return dp[n] = n;

  int best = INT_MAX;
  for(int i=8; i>=0; i--) {
    if(six[i] <= n) {
      best = min(dfs(n-six[i]) + 1, best);
      break;
    }
  }
  for(int i=8; i>=0; i--) {
    if(nine[i] <= n) {
      best = min(dfs(n-nine[i]) + 1, best);
      break;
    }
  }
  return dp[n] = best;
}

int main (int argc, char*argv[]) {
  int s = 1;
  int n = 1;
  for(int i=0; i<9; i++) {
    six[i] = s;
    nine[i] = n;
    s *= 6;
    n *= 9;
  }

  for(int i=0; i<100005; i++) dp[i] = -1;

  cin >> n;
  cout << dfs(n) << endl;;
  return 0;
}


Measured memory_bytes: 640
#include<stdio.h>

void turn(int *DICE,char com);

int main(void){
int i;
int DICE[6];
char com[105];
for(i=0;i<6;i++){scanf("%d",&DICE[i]);}
scanf("%s",com);
i=0;
while(com[i]!='\0'){
	turn(&DICE[0],com[i]);
	i++;
	}

printf("%d\n",DICE[0]);
return 0;
}

void turn(int *DICE,char com){
int temp;
switch(com){
	case 'N':
		temp     =*DICE;
		*DICE    =*(DICE+1);
		*(DICE+1)=*(DICE+5);
		*(DICE+5)=*(DICE+4);
		*(DICE+4)=temp;
		break;
	case 'S':
		temp     =*DICE;
		*DICE    =*(DICE+4);
		*(DICE+4)=*(DICE+5);
		*(DICE+5)=*(DICE+1);
		*(DICE+1)=temp;
		break;
	case 'E':
		temp     =*DICE;
		*DICE    =*(DICE+3);
		*(DICE+3)=*(DICE+5);
		*(DICE+5)=*(DICE+2);
		*(DICE+2)=temp;
		break;
	case 'W':
		temp     =*DICE;
		*DICE    =*(DICE+2);
		*(DICE+2)=*(DICE+5);
		*(DICE+5)=*(DICE+3);
		*(DICE+3)=temp;
		break;
	}
}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    string S;
    cin >> S;

    int ans = 0;
    rep (i, S.size()-1) {
        if (S[i] != S[i+1]) {
            ans++;
        } 
    }

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

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007LL;
const int INF = LLONG_MAX;

string mymax(string &a, string &b){
    if(a.size() > b.size()){
        return a;
    }else if(a.size() < b.size()){
        return b;
    }else{
        return (a < b ? b : a);
    }
}

string f(int l, int r, string &s, vector<vector<string> > &dp){
    //cout << l << " " << r << endl;
    string res = "";
    if(dp[l][r] != "monkukui") return dp[l][r];
    if(l >= r){
        res = "invalid";
        dp[l][r] = res;
        return "invalid";
    }

    if(r - l == 1){
        if('0' <= s[l] && s[l] <= '9'){
            res += s[l];
            dp[l][r] = res;
            return res;
        }else if(s[l] == '?'){
            res = "9";
            dp[l][r] = res;
            return res;
        }else{
            res = "invalid";
            dp[l][r] = res;
            return res;
        }
    }

    if(s[l] == '0'){
        res = "invalid";
        dp[l][r] = res;
        return "invalid";
    }

    //全部数字にできるなら
    bool ok = true;
    for(int i = l; i < r; i++){
        if('0' <= s[i] && s[i] <= '9') res += s[i];
        else if(s[i] == '?') res += '9';
        else ok = false;
    }


    if(ok){
        dp[l][r] = res;
        return res;
    }else{

        res = "";
        for(int i = l; i < r; i++){   

            if(s[i] != '?' && s[i] != ',') continue;
            if(s[l] != '?' && s[l] != 'L' && s[l] != 'R') continue;
            if(s[l + 1] != '?' && s[l + 1] != '(') continue;
            if(s[r - 1] != '?' && s[r - 1] != ')') continue;
            
            string L = f(l + 2, i, s, dp);
            string R = f(i + 1, r - 1, s, dp);
            if(L == "invalid" || R == "invalid") continue;
            //cout << i << " " << L << " " << R << endl;
            
            if(s[l] == 'L' || s[l] == '?'){
                res = mymax(res, L);
            }
            if(s[l] == 'R' || s[l] == '?'){
                res = mymax(res, R);
            }
        }
    }

    if(res == ""){
        res = "invalid";
        dp[l][r] = res;
        return "invalid";
    }
        
    dp[l][r] = res;
    return res;
}

signed main(){
    
    string s; cin >> s;
    int n = (int)s.size();
    vector<vector<string> > dp(n + 1, vector<string> (n + 1, "monkukui"));
    string ans = f(0, n, s, dp);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3292
#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>
#include <cassert>

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)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main(){
  int W, N;
  const int MAX_N = 100001;
  while(cin >> N >> W){
    int b = 1, e = W;
    int cnt = W;
    vector<bool> used(MAX_N, false);
    REP(i, W) used[i + 1] = true;
    vector<int> ans;
    while(e <= N){
      ans.push_back(cnt);
      for(int i = 1; i * i <= b; i++)if(b % i == 0){
        if(used[i] && b + 2 * i > (e + 1)){
          used[i] = false;
          cnt--;
        }
        if(used[b / i] && b + 2 * (b / i) > e + 1){
          used[b / i] = false;
          cnt--;
        }
      }
      b++; e++;
      assert(!used[e]);
      used[e] = true;
      cnt++;
      for(int i = 1; i * i <= e; i++) if(e % i == 0){
        if(!used[i] && e - i >= b){
          used[i] = true;
          cnt++;
        }
        if(!used[e / i] && e - (e / i) >= b){
          used[e / i] = true;
          cnt++;
        }
      }
    }
    REP(i, ans.size()) {
      cout << ans[i];
      if(i == ans.size() - 1) cout << endl;
      else cout << " ";
    }
  }
  return 0;
}

Measured memory_bytes: 1688
def main():
    a, b, c, x, y = map(int, input().split())

    ans = 1000000007
    for i in range(100001):
        cost = c * i * 2 + a * max(0, x - i) + b * max(0, y - i)
        if cost < ans:
            ans = cost

    print(ans)

if __name__ == '__main__':
    main()


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

int main() {
    string str;
    int count[26];
    for (int i = 0; i < 26; i++) {
        count[i] = 0;
    }
    while (getline(cin, str)) {
        for (int i = 0; i < str.size(); i++) {
            if (str[i] >= 'a' && str[i] <= 'z') {
                count[str[i] - 'a']++;
            }
            if (str[i] >= 'A' && str[i] <= 'Z') {
                count[str[i] - 'A']++;
            }
        }
    }
    for (int i = 0; i < 26; i++) {
        printf("%c : %d\n", 'a' + i, count[i]);
    }
    return 0;
}


Measured memory_bytes: 3284
function main()
  
  N = parse(Int,readline())
  B = map(x -> parse(Int,x), split(readline()))
  
  ans = B[1]
  
  for i in 1:N-1
    
    if i != N-1 && B[i] <= B[i+1]
      ans += B[i]
    elseif i != N-1
      ans += B[i+1]
    else
      ans += B[N-1]
    end
    
  end
  
  println(ans)
  
end

main()

Measured memory_bytes: 110476
#!/usr/bin/env python3
import sys


def solve(r: int):
    print(3 * r ** 2)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    r = int(next(tokens))  # type: int
    solve(r)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940