akhauriyash/Code-Regression huggingface dataset:
// finish date: 2018/07/20
#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;


int main() {
    vi A(3);
    rep(i,3) cin>>A[i];
    sort(A.begin(),A.end());

    cout<<A[2]-A[0]<<endl;
    


    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,i,j;
  cin>>n;
  vector<int> v(n);
  for(i=0;i<n;i++){
    cin>>v[i];
  }
  int dp[n+1];
  dp[0]=dp[1]=0;
  dp[2]=abs(v[0]-v[1]);
  for(i=3;i<=n;i++){
  dp[i]=min(abs(v[i-1]-v[i-2])+dp[i-1],abs(v[i-3]-v[i-1])+dp[i-2]);
  }
  cout<<dp[n];
}
  
  

Measured memory_bytes: 4024
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    ll n;
    cin >> n;
    vll w(n), s(n + 1);
    REP(i, n){
        cin >> w[i];
        s[i + 1] = s[i] + w[i];
    }
    ll d = 1e10;
    REP(i, n){
        d = min(d, abs(s[i + 1] - (s[n] - s[i + 1])));
    }
    cout << d << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
 
typedef struct Node* NodePointer;
 
typedef struct Node {
  int key;
  NodePointer next;
} Node;
 
 
NodePointer child[100001];
NodePointer tail[100001];
int N;
int parent[100001];
char isLeaf[100001];
 
NodePointer makeNode(int key) {
  NodePointer p = (NodePointer)malloc(sizeof(Node));
  p->key = key;
  p->next = NULL;
  return p;
}
 
void add(int n, int x) {
  tail[n]->next = makeNode(x);
  tail[n] = tail[n]->next;
}
 
int calcDepth(int i) {
  if(parent[i] == -1) return 0;
  return calcDepth(parent[i]) + 1;
}
 
int main() {
  int i,j, k;
  int c, id, depth, flag;
  NodePointer p;
  scanf("%d", &N);
  for(i = 0; i < N; ++i) {
    parent[i] = -1;
    isLeaf[i] = 1;
    child[i] = makeNode(-1);
    tail[i] = child[i];
  }
  for(i = 0; i < N; ++i) {
    scanf("%d %d", &id, &k);
    while(k--) {
      scanf("%d", &c);
      parent[c] = id;
      add(id,c);
      isLeaf[id] = 0;
    }
  }
  for(i = 0; i < N; ++i) {
    depth = calcDepth(i);
    flag = 0;
    p;
    printf("node %d: parent = %d, depth = %d, ", i, parent[i], depth);
    if(depth == 0) {
      printf("root, ");
    } else if(isLeaf[i]) {
      printf("leaf, ");
    } else {
      printf("internal node, ");
    }
    printf("[");
    for(p = child[i]->next; p != NULL; p = p->next) {
      if(flag) printf(", ");
      else flag = 1;
      printf("%d", p->key);
    }
    printf("]\n");
  }
  return 0;
}

Measured memory_bytes: 4856
#include<iostream>
#include<cmath>
using namespace std;
int main(){
	int i,j,n,m,no,len,Min;
	cin>>n>>m;
	int a[n+5],b[n+5];
	for(i=1;i<=n;i++)cin>>a[i]>>b[i];
	int c[m+5],d[m+5];
	for(i=1;i<=m;i++)cin>>c[i]>>d[i];
	for(i=1;i<=n;i++){
		no=1;
		Min=abs(a[i]-c[1])+abs(b[i]-d[1]);
		for(j=2;j<=m;j++){
			len=abs(a[i]-c[j])+abs(b[i]-d[j]);
			if(len<Min){
				Min=len;
				no=j;
			}
		}
		cout<<no<<endl;
	}
	return 0;
}

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

int main() {
    string s; cin >> s;
    for(int i=0; i<s.size(); i++){
        if(i==s.size()-2){
           if(s.at(i)==s.at(i+1)){
            cout << i+1 << " " << i+2 << endl;
            return 0;
           } 
           break;
        }
        else if(s.at(i)==s.at(i+1) || s.at(i)==s.at(i+2)){
            cout << i+1 << " " << i+3 << endl;
            return 0;
        }
    }

    cout << -1 << " " << -1 << endl;
    return 0;
}


Measured memory_bytes: 512
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("Ofast")
//#pragma GCC optimization ("unroll-loops")

//#pragma comment(linker,"/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

//order_of_key(k): Number of items strictly smaller than k .
//find_by_order(k): K-th element in a set (counting from zero).
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define full(x,n) x,x+n+1
#define full(x) x.begin(),x.end()
#define finish return 0

#define putb push_back
#define f first
#define s second

//logx(a^n)=loga(a^n)/logx(a)
//logx(a*b)=logx(a)+logx(b)
//logx(y)=log(y)/log(x)

#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define putf push_front
#define gainb pop_back

#define gainf pop_front
#define len(x) (int)x.size()

// 1/b%mod=b^(m-2)%mod
// (a>>x)&1==0
// a^b=(a+b)-2(a&b)

typedef double db;
typedef long long ll;

const int ary=2e5+5;
const int mod=1e9+7;
const ll inf=1e18;

using namespace std;
using namespace __gnu_pbds;
ll n,p[10][10];
ll ans;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++){
		int x=i;
		while(x){
			if(x<=9){
				break;
			}
			x/=10;
		}
		p[x][i%10]++;
	}
	for(int i=1;i<=9;i++){
		for(int j=1;j<=9;j++){
			ans+=p[i][j]*p[j][i];
		}
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxd=1e5+10;
ll p[maxd],a[maxd],sum,ans;
int t[maxd],tot,n;
void insert(ll x){
	for(int i=1;i<=tot;i++){
		if((x>>t[i])&1){
			if(p[i])x^=p[i];
			else{
				p[i]=x;
				break;
			}
		}
	}
}
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=1;i<=n;i++){
		sum^=a[i];
	}
	for(int i=60;i>=0;i--){
		if(((sum>>i)&1)==0){
			t[++tot]=i;
		}
	}
	for(int i=1;i<=n;i++){
		insert(a[i]);
	}
	for(int i=1;i<=tot;i++){
		if(((ans>>t[i])&1)==0)ans^=p[i];
	}
	cout<<(ans+(sum^ans))<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>

#define int long long

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)

#define INF (1e9)

using namespace std;

int a, b, c;

signed main()
{
    string s;
    cin >> s;
    REP(i, 3)
    {
        char ch = s.at(i);
        switch (ch)
        {
            case 'a':
                ++a;
                break;
            case 'b':
                ++b;
                break;
            case 'c':
                ++c;
                break;
        }

    }

    if (a == 1 && b == 1 && c == 1)
    {
        puts("Yes");
    }
    else
    {
        puts("No");
    }

    return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n,m=map(int,readline().split())
d = map(int,read().split())
data = list(zip(d,d))
data.sort(key=lambda x:x[0])
c=0
cost=0
for x,y in data:
  if m-c<=y:
    cost+=(m-c)*x
    break
  else:
    c+=y
    cost+=y*x
print(cost)



Measured memory_bytes: 27496
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n;
    cin >> n;
    int in;
    REP(i,0,n) {
        cin >> in;
        if (in % 2) {
            cout << "first" << endl;
            return;
        }
    }
    cout << "second" << endl;

}

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

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<string>
#include<cstdio>
#include<queue>
#include<functional>
using namespace std;
int main() {
	int n; cin >> n;
	long long a=0, b=1;
	for (int i = 0; i < n; ++i) {
		int q, x; cin >> q >> x;
		if (q == 1) {
			b *= x;
			a *= x;
		}
		else if (q == 2) {
			a -= x;
		}
		else {
			a += x;
		}
	}
	cout << a << " " << b << endl;
	return 0;
}


Measured memory_bytes: 3120
import collections
q=collections.deque()
h,w=map(int,input().split())
S=[]
for _ in range(h):
    s=input()
    S.append(s)
went=[[0]*w for _ in range(h)]
l=[]
def walk(x,y):
    if x<=h-2:
        if S[x+1][y]=='.' and (x+1,y)!=(ih,iw) and went[x+1][y]==0 or went[x+1][y]>went[x][y]+1:
            went[x+1][y]=went[x][y]+1
            q.append((x+1,y))
    if y<=w-2:
        if S[x][y+1]=='.' and (x,y+1)!=(ih,iw) and went[x][y+1]==0 or went[x][y+1]>went[x][y]+1:
            went[x][y+1]=went[x][y]+1
            q.append((x,y+1))
    if y>=1:
        if S[x][y-1]=='.' and (x,y-1)!=(ih,iw) and went[x][y-1]==0 or went[x][y-1]>went[x][y]+1:
            went[x][y-1]=went[x][y]+1
            q.append((x,y-1))
    if x>=1:
        if S[x-1][y]=='.' and (x-1,y)!=(ih,iw) and went[x-1][y]==0 or went[x-1][y]>went[x][y]+1:
            went[x-1][y]=went[x][y]+1
            q.append((x-1,y))
        
for ih in range(h):
    for iw in range(w):
        if S[ih][iw]=='.':
            went=[[0]*w for _ in range(h)]
            q.append((ih,iw))
            while q:
                (a,b)=q.pop()
                walk(a,b)
            
            ll=[]
            for i in range(h):
                ll.append(max(went[i]))
            l.append(max(ll))
            
print(max(l))

Measured memory_bytes: 96024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A , B , C;
  cin >> A >> B >> C;
  int answer;
  if ( A == B ) {
    answer++;
  }
  if ( B == C ) {
    answer++;
  }
  if ( C == A ) {
    answer++;
  }
  if ( answer == 1 ) {
   cout << "Yes" << endl;
  }
  if ( answer != 1 ) {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import numpy as np
s=list(map(int, input().split()))
a =s[0]
b =s[1]
h =s[2]
m=s[3]
min = h*60 + m

rada = np.radians(90-min*0.5)
acos = np.cos(rada)
x1 = a * acos
asin = np.sin(rada)
y1 = a * asin

radb = np.radians(90-m*6)
bcos = np.cos(radb)
x2 = b * bcos
bsin = np.sin(radb)
y2 = b * bsin

A = np.array([x1, y1])
B = np.array([x2, y2])
u = B-A
np.linalg.norm(u)
print(np.linalg.norm(u))

Measured memory_bytes: 27304
//#include "stdafx.h"
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>
#include <cstdint>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define	BitSetV(Val,Bit)		((Val) |= (Bit))			
#define	BitTstV(Val,Bit)		((Val) & (Bit))				
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long long int	QWORD;
typedef unsigned long long		SQWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int main()
{
	int T[2];
	cin >> T[0] >> T[1];

	ll speed[2][2];
	cin >> speed[0][0] >> speed[0][1];
	cin >> speed[1][0] >> speed[1][1];

	ll oneDist[2];
	REP(i, 2) {
		oneDist[i]  = speed[i][0] * T[0];
		oneDist[i] += speed[i][1] * T[1];
	}

	if (oneDist[0] == oneDist[1]) {
		cout << "infinity" << endl;
		return 0;
	}

	ll diffDist;
	ll diffKyori;
	ll ans = 0;
	if (oneDist[0] < oneDist[1]) {
		diffDist = oneDist[1] - oneDist[0];
		diffKyori = (speed[0][0] - speed[1][0]) * T[0];
	} else {
		diffDist = oneDist[0] - oneDist[1];
		diffKyori = (speed[1][0] - speed[0][0]) * T[0];
	}

	if (0 < diffKyori) {
		ans = 2 * (diffKyori / diffDist);
		ll amari = diffKyori % diffDist;
		if (0 < amari) ans++;
	}

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


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int n,k;
    cin >> n >> k;
    long long int h[n];
    for(int i = 0;i < n;i++)
    {
        cin >> h[i];
    }
    sort(h,h + n,greater<int>());
    long long int ans = 0;
    for(int i = k;i < n;i++)
    {
        ans += h[i];
    }
    cout << ans << "\n";
    
    return 0;
}

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

int main(void){
  int n;
  int a,b;
  while(1){
    cin>>n;
    int scoreA=0;
    int scoreB=0;
    if(n==0){return 0;}
    for(int i=0;i<n;i++){
      cin>>a>>b;
      if(a>b){
        scoreA+=(a+b);
      }
      else if(a<b){
        scoreB+=(a+b);
      }
      else{
        scoreA+=a;
        scoreB+=b;
      }
    }
    cout<<scoreA<<" "<<scoreB<<endl;
  }
}



Measured memory_bytes: 3088
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll t,d,l;
  while(cin>>t>>d>>l,t+d+l){
    ll ans=0;
    ll nokori=0;
    for(int i=0;i<t;i++){
      ll x;cin>>x;
      if(nokori>0)ans++;
      nokori--;
      if(l<=x)nokori=d;
      //cout<<nokori<<endl;

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



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

using namespace std;

int main() {
    string S;
    cin >> S;
    string ans;
    if (S == "Sunny") ans = "Cloudy";
    else if (S == "Cloudy") ans = "Rainy";
    else ans = "Sunny";
    cout << ans << endl;
    return 0;
}


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

int F[50];

int main() {

    int n;
    cin >> n;
    F[0] = 1;
    F[1] = 1;
    for (int i = 2; i < 45; i++) {
        F[i] = F[i-1] + F[i-2];
    }
    cout << F[n] << '\n';
}



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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    int l = s.size();
    vector<vector<int> > dp(l + 1, vector<int>(13));
    int p = 13;
    ll m = 1;
    dp[0][0] = 1;
    rep (i, s.size()) {
        ll t;
        if (s[i] == '?') {
            rep (j, 10) {
                t = m * j % p;
                rep (k, 13) {
                    dp[i + 1][(k + t) % p] += dp[i][k];
                    dp[i + 1][(k + t) % p] %= MOD;
                }
            }
        } else {
            t = m * (s[i] - '0') % p;
            rep (j, 13) {
                dp[i + 1][(j + t) % p] += dp[i][j];
                dp[i + 1][(j + t) % p] %= MOD;
            }
        }
        m *= 10;
        m %= p;
    }
    cout << dp[l][5] << endl;
    
    return 0;
}



Measured memory_bytes: 8912
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"
int main() {
	while (1) {
		int M, N; cin >> M >> N;
		if (!M)break;
		vector<int>as;
		for (int i = 0; i < N; ++i) {
			int a; cin >> a;
			as.emplace_back(a);
		}

		int amin = *max_element(as.begin(),as.end())-1; int amax = 1500001;
		while (amin + 1 != amax) {
			int amid = (amin + amax) / 2;
			{
				int h = 0;
				int num = 0;
				for (int b = 0; b < N; ++b) {
					if (as[b] + num > amid) {
						h++;
						num = as[b];
					}
					else {
						num += as[b];
					}
				}
				if (h >= M) {
					amin = amid;
				}
				else {
					amax = amid;
				}
			}
		}
		cout << amax << endl;
	}
	return 0;
}

Measured memory_bytes: 3076
// first second push_back unordered return continue break vector visited check flag bool while iterator begin end lower_bound upper_bound temp true false ll_MAX ll_MIN insert erase clear pop push compare ll64_MAX ll64_MIN  reverse replace stringstream string::npos length substr front priority_queue
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()
const ll mod = 1e9 + 7 ;
const ll inf =
 1e9 + 5 ;
 //1e18L + 5;
const ll nax = 2e5 + 5;
void min_self(ll&a , ll b){a=min(a,b);}
void max_self(ll&a , ll b){a=max(a,b);}
void add_self(ll&a , ll b){a=(a+b)%mod;}
//#define (x)  get<0>(x) 
//#define (x)  get<1>(x)
//#define (x)  get<2>(x)
vector<ll> tree , lazy  ; 
ll base ;
ll poll_query(ll p){
	ll res = tree[p+base];
	ll x = p + base ; 
	while(x>0){
		// cout << x << endl;
		res += lazy[x];
		x/=2;
	}
	return res ;
}

void update(ll l , ll r , ll val ){
	l += base ;
	r += base ; 
	lazy[l]+=val;
	if(l!=r)lazy[r]+=val;
	while(l+1 < r){
		if(!(l&1))lazy[l+1] += val ;
		if(r&1)lazy[r-1] += val;
		l/=2 ;
		r/=2;
	}
}




signed main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll n ,d , a ;cin >> n >> d >> a ; 
vector<pair<ll,ll>> v(n) ; 
for(ll i = 0 ; i<n ; i++){
	ll k , l ; 
	cin >> k >> l ; 
	 l = (a-1 + l )/a ; 
	 v[i] = {k , l };
}
sort(all(v));
ll ans = 0 ;
base = 1 ; 
while(base < n)base *=2 ; 
tree.resize(2*base) ; 
lazy.resize(2*base ) ;

for(ll i = 0  ;i< n ; i++){
	ll x = i + base ; 
	// tree[x] = v[i].second;
	while(x>0){
		tree[x] += v[i].second ; 
		x/=2;
	}
}

for(ll x = 0 ; x < n ; x ++){

ll res = 0 ;
// find res ;
res = poll_query(x) ; 
// cout << x << " " << res << endl;
if(res <=0  )continue ; 

ll low = x , high = n-1; 
ll ok ; 
while(low <= high ){
	ll mid = low + (high - low) / 2; 
	if(v[mid].first <= v[x].first + 2*d){
		ok = mid;  
		low = mid + 1; 
	}
	else{
		high = mid - 1 ;
	}
}

// update x....ok ( -res ) ;
update(x , ok  , -res) ;
ans += res;

}
cout << ans; 



	

	
}

Measured memory_bytes: 11648
#include<stdio.h>


int n;
int A[20000+20];


int cular(int i,int m){
     int res;
     if(m == 0)  return 1;
     if(i >= n)  return 0;
      res = cular(i + 1, m) || cular(i + 1, m - A[i]);
      return res;
}

int main(){
     int i,q,w,e,r;
     int C[8000+80];
scanf("%d/n",&n);
     for(i=0;i<n;i++){
	 
	scanf("%d",&A[i]);
	}
scanf("%d",&q);
     for(i=0;i<q;i++){
	 scanf("%d",&C[i]);
if (cular(0,C[i]) == 1)
     printf("yes\n");
else 
     printf("no\n");

}

return 0;
}


Measured memory_bytes: 2140
#include<stdio.h>
int main(){
	int room[10][3][4] = {0};
	int n,b,f,r,v;
	/*入力部*/
	scanf("%d",&n);
	for (int i = 0; i < n; ++i)
	{
		scanf("%d %d %d %d",&b,&f,&r,&v);
		room[--r][--f][--b] += v;
	}
	/*出力部*/
	for (int i = 0; i < 4; ++i)
	{
		for (int  j= 0; j < 3; ++j)
		{
			for (int k= 0; k < 10; ++k)
			{
				printf(" %d", room[k][j][i]);
			}
			printf("\n");
		}
		if (i == 3)break;
		printf("####################\n");
	}
	return 0;
}


Measured memory_bytes: 2036
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };

void  bubbleSort(int number[], int length);

int main() {
	int N;
	int A[100002];
	int rank[100002];

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

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

	for (int i = 0; i < N; i++) {
		printf("%d ", rank[i]);
	}
}

/*         提出前の確認事項

・デバッグ用の関数は＜＜コメント化＞＞しているか？
・すべての＜＜入力例＞＞は試したか？
・＜＜限界値分析＞＞はしたか？
・＜＜出力の改行＞＞の有無は確認したか？
・文字列の＜＜スペル＞＞は確認したか？
　　　　　　　　↓
	 ＜＜提出先＞＞に注意して提出！！
*/

Measured memory_bytes: 1536
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

/*BigInteger
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>
namespace xxx = boost::multiprecision;
using Bint = xxx::cpp_int;
using Real = xxx::number<xxx::cpp_dec_float<1024>>;
*/

#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0LL, sizeof(x))
#define mm(x) memset((x), -1LL, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define Bit(n) (1LL << (n))
#define Bitset(a, b) (a) |= (1LL << (b))
#define Bitunset(a, b) (a) &= ~(1LL << (b))
#define Bitcheck(a, b) ((((a) >> (b)) & 1LL) == 1LL)
#define Bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
constexpr int INF = (int)1e18;
constexpr int MOD = (int)1e9 + 7;
constexpr double PI = (double)acos(-1);
constexpr double EPS = (double)1e-10;
constexpr int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
constexpr int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
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); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
} Accelerate_Cin;

signed main() {
  int N;
  cin >> N;
  vector<int> a(N), b(N);
  for (int i = 0; i < N; i++) cin >> a[i];
  for (int i = 0; i < N; i++) cin >> b[i];

  int tmp = 0;
  for (int i = 0; i < N; i++) {
    if (a[i] < b[i]) {
      tmp += (b[i] - a[i]) / 2;
    } else if (a[i] > b[i]) {
      tmp -= a[i] - b[i];
    }
  }

  if (tmp >= 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] ns = new int[n];
		int s = 0;

		for(int i = 0; i < n; i++) ns[i] = sc.nextInt();

		for(int i = 0; i < n - 1; i++) {
			for(int j = 1 + i; j < n; j++) {
				s += ns[i] * ns[j];
			}
		}
		System.out.println(s);
	}
}

Measured memory_bytes: 35672
a = gets.chomp
b = gets.chomp

match = false
for i in 0...a.length
  flag = true
  for j in 0...a.length
    idx = (i+j) % a.length
    if a[idx] != b[j]
      flag = false
      break
    end
  end

  if flag
    match = true
  end
end

if match
  puts 'Yes'
else
  puts 'No'
end


Measured memory_bytes: 1916
use std::vec::Vec;
use std::cmp::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
  let (D, N) = {
    let v: Vec<u64> = read_vec();
    (v[0], v[1])
  };
  let mut a: u64 = 1;
  for _ in 0..D {
    a *= 100;
  }

  if N <= 99 {
    println!("{}", N * a);
  } else {
    println!("{}", 101 * a);
  }
}


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

int main() {
  int N;
  scanf("%d", &N);
  int c[N],s[N],f[N];
  for (int i = 0; i < N; ++i) {
    scanf("%d%d%d", &c[i],&s[i],&f[i]);
  }

  for (int i = 0; i < N-1; ++i){
    int time = 0;
    for (int j = i; j < N-1; ++j){
      if(time<=s[j]) time=s[j]+c[j];
      else {
        while(s[j]%f[j]!=time%f[j]) ++time;
        time += c[j];
      }
      // cout << time << endl;
    }
    cout << time << endl;
  }

  cout << 0 << endl;

}



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

int main()
{
    int a, b, c, d, i;
    cin >> a >> b >> c >> d;

    while (c > 0 && a > 0)
    {
        c = c - b;
        if (c > 0)
        {
            a = a - d;
            if (a < 1)
            {
                cout << "No" << endl;
            }
        }
        else
        {
            cout << "Yes" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3620
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    int n; cin>>n;
    ll a[100010];
    ll s=0;
    ll s1=0;
    for(int i=0; i<n; i++){
        cin>>a[i];
        s+=a[i];
        if(i&1) s1+=a[i];
    }
    s/=2;
    ll x[100010];
    x[0]=s-s1;
    for(int i=1; i<n; i++){
        x[i]=a[i-1]-x[i-1];
    }
    for(int i=0; i<n; i++){
        cout<<2*x[i];
        if(i<n-1) cout<<" ";
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 2816
from queue import Queue

n, m = map(int, input().split())
ab = [map(int, input().split()) for _ in range(m)]
a, b = [list(i) for i in zip(*ab)]
L = [-1]*n
neighbor =[[] for i in range(n)]
for i in range(m):
  neighbor[a[i]-1].append(b[i])
  neighbor[b[i]-1].append(a[i])
  
q = Queue()

q.put([1])
L[0] = 0

while not q.empty():
  pos = q.get()
  valid_pos =[]
  for p in pos:
    for m in neighbor[p-1]:
      if L[m-1] == -1:
        L[m-1] = p
        valid_pos.append(m)
  if len(valid_pos) != 0:
    q.put(valid_pos)

print('Yes')    
for i in range(n-1):
  print(L[i+1])

Measured memory_bytes: 124064
//#define _USE_MATH_DEFINES
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wmissing-declarations"
#define FINAL_OUT(x) {cout << (x) << '\n'; exit(0); }
inline int safe_mul(const int x, const int y) __attribute__ ((warn_unused_result));


int main()
{
//    freopen("in.txt","r", stdin);
//    freopen("out.txt", "w", stdout);
//    cout << fixed << setprecision(20);
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    if (n & (n - 1)) {
        cout << "Yes\n";
        if (n & 1) {
            cout << "1 2" << endl;
            for (int i = 2; i <= n; i += 2) {
                cout << i << ' ' << i + 1 << '\n';
                cout << i + 1 << ' ' << n + 1 << '\n';
                cout << n + 1 << ' ' << n + i << '\n';
                cout << n + i << ' ' << n + i + 1 << '\n';
            }
        } else {
            cout << "1 2" << endl;
            for (int i = 2; i < n; i += 2) {
                cout << i << ' ' << i + 1 << '\n';
                cout << i + 1 << ' ' << n + 1 << '\n';
                cout << n + 1 << ' ' << n + i << '\n';
                cout << n + i << ' ' << n + i + 1 << '\n';
            }
            for (int t = 1; t <= n; ++t) {
                if ((n ^ (2*t)) < n) {
                    cout << n << ' ' << 2 * t + 1 << '\n';
                    cout << n + n << ' ' << n + (n ^ (2 * t)) << '\n';
                    break;
                }
            }
        }
        return 0;
    }
    FINAL_OUT("No");
}


Measured memory_bytes: 2816
import java.util.Scanner;

class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        String p = sc.nextLine();
        p = p + p;
        String s = sc.nextLine();

        int lenp = p.length();
        int lens = s.length();

        boolean result = false;
        for (int i = 0; i <= lenp - lens; i++) {
            if (p.substring(i, i + lens).equals(s)) {
                result = true;
            }
        }
        System.out.println((result ? "Yes" : "No"));

    }



}


Measured memory_bytes: 26364
#include <algorithm>
#include <queue>
#include <vector>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#define ll long long
#define N 1000000005
using namespace std;
int main()
{
    long long  n;
    scanf("%lld",&n);
    int a[200005];
    int i;
    for( i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a,a+n);
    for(int j=0; j<n; j++)
    {
        if(a[j]==a[j+1])
        {
            printf("NO\n");
            return 0;
        }

    }
    printf("YES\n");
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(long long i=s;i<n;i++)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
const double pi = acos(-1.0);
const ll mod = pow(10,9) + 7;
const ll INF = pow(2,31) - 1;

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}

int main()
{
    string s;
    cin >> s;
    rep(i,s.size())cout << 'x';
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
s = [int(input()) for _ in range(n)]
s.sort()

ans = sum(s)
if ans % 10 == 0:
    for i in range(n):
        if s[i] % 10 != 0:
            ans -= s[i]
            break
    if ans % 10 == 0:
        ans = 0

print(ans)


Measured memory_bytes: 2940
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}
int read() {
	int tmp;
	cin >> tmp;
	return tmp;
}
int xor128() {
	static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	int t = (x xor (x << 11));
	x = y; y = z; z = w;
	return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}

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

	int n;
	cin >> n;
	int a[205][205];
	rep(i, n) {
		rep(j, n) {
			char c;
			cin >> c;
			a[i][j] = c - '0';
		}
	}

	int ans = -1;
	rep(i, n) {
		int nowcnt = 0;
		int dat[205];
		rep(j, n) dat[j] = -2;
		dat[i] = nowcnt;
		while (1) {
			rep(j, n) {
				if (dat[j] == nowcnt) {
					rep(k, n) {
						if (a[j][k] && dat[k] != nowcnt && dat[k] != nowcnt - 1&&dat[k]!=nowcnt+1) {
							if (dat[k] != -2) {
								goto bou;
							}
							dat[k] = nowcnt + 1;
						}
					}
				}
			}
			rep(j, n) {
				rep(k, n) {
					if (dat[j] == dat[k] && dat[j] != -2 && a[j][k]) {
						goto bou;
					}
				}
			}
			nowcnt++;
			bool finish = true;
			rep(j, n) {
				if (dat[j] == -2) {
					finish = false;
					break;
				}
			}
			if (finish) break;
		}
		ans = max(ans, nowcnt + 1);
	bou:;
	}
	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll zero = 0;
ll INF = 10000000000;

int main(){
    ll N,A,B;
    cin >> N >> A >> B;
    ll ans = max(B*N - A*N +1- 2*(B-A), zero);
    printf("%lld\n", ans);
    
}

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

int main(void){
  string s;
  cin >> s;

  for(int i=0; i < s.length(); i++){
    s[i] = 'A' + (((s[i] + 3) % 26)+7) % 26;
  }
  cout << s << endl;
  return 0;
}

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

using namespace std;

using ll = long long;
const int MOD = 998244353;

// dp[i][j] => starting from i items already considered and sum of such items(taken in set both U and T) is j

int main()
{
    int n, s;
    cin >> n >> s;
    vector<int> arr(n);
    for(auto& x : arr) cin >> x;
    vector<vector<ll>> dp(n + 1, vector<ll>(s + 1, 0));
    dp[0][0] = 1;
    for(int i = 0; i < n; i++) {
        for(int sum = 0; sum <= s; sum++) {
            dp[i + 1][sum] += 2 * dp[i][sum]; // no of sets of length (i + 1) in T is doubled since all sets of dp[i][sum] are inclued in dp[i + 1][sum] and same sets with a[i] included in T
            dp[i + 1][sum] %= MOD;
            if(sum + arr[i] <= s) {
                dp[i + 1][sum + arr[i]] += dp[i][sum];
                dp[i + 1][sum + arr[i]] %= MOD;
            }
        }
    }
    cout << dp[n][s];
    return 0;
}


Measured memory_bytes: 73712
#include<iostream>

using namespace std;

int main(){
    int n, c = 0, i = 0; cin >> n;
    if(1 <= n && n < 10){ c+=n; cout << c << endl; return 0;}
    if(10 <= n && n < 100){ c+=9; cout << c << endl; return 0;}
    if(100 <= n && n < 1000 ){ c+=n+9-99; cout << c << endl; return 0;}
    if(1000 <= n && n < 10000 ){ c+=9+900; cout << c << endl; return 0;}
    if(10000 <= n && n < 100000 ){ c+=n+9+900-9999; cout << c << endl; return 0;}
    if(100000 <= n && n < 1000000 ){ c+=9+900+90000; cout << c << endl; return 0;}
    return 0;
}

Measured memory_bytes: 256
//ヘッダファイル
#include<stdio.h>

//エントリポイント
int main(void)
{	
	int n;
	int a[200000]={};
	
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",a+i);
	}
	
	int first,fi;
	int second;
	
	if(a[0]>=a[1]){
		first=a[0];fi=0;
		second=a[1];
	}else{
		first=a[1];fi=1;
		second=a[0];
	}
	
	for(int i=2;i<n;i++){
		if(a[i]>=first){
			second=first;
			first=a[i];fi=i;
		}else if(a[i]>=second){
			second=a[i];
		}
	}
	
	for(int i=0;i<n;i++){
		printf("%d\n",i!=fi?first:second);
	}
	
	return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/replace.hpp>
using namespace std;
using namespace boost::algorithm;
#define rep(i, n) for (int i = 0; i < n; ++i)

int main() {
  int a;
  string s;
  cin >> a >> s;
  cout << (a >= 3200 ? s : "red") << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		String s = sc.next();
		if(s.equals("AAA")||s.equals("BBB")) {
			System.out.println("No");
		}else {
			System.out.println("Yes");
		}

	}
}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std; 
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair <int,int> PII;
typedef pair <ll, ll> PLL;
typedef pair <int,string> PIS;
typedef vector <int> vec;
typedef priority_queue<int> PQ;
#define endl '\n'
#define pi 3.141592653589793
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define fori(z,n)  for(int i=z;i<n;i++)
#define fork(z,n)  for(int k=z;k<n;k++)
#define forii(z,n) for(int i=z;i<=n;i++)
#define forkk(z,n) for(int k=z;k<=n;k++)
int maxElement(int arr[],int n)
{
    int maxi=arr[0];
    for(int i=1;i<n;i++)
    {
        if(arr[i]>maxi)
            maxi=arr[i];
    }
    return maxi;
}
int minElement(int arr[],int n)
{
    int mini=arr[0];
    for(int i=1;i<n;i++)
    {
        if(arr[i]<mini)
            mini=arr[i];
    }
    return mini;
}
string trim(const string& str)
{
    size_t first = str.find_first_not_of(' ');
    if (string::npos == first)
    {
        return str;
    }
    int last = str.find_last_not_of(' ');
    return str.substr(first, (last - first + 1));
}
int main() 
{ 
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;cin>>n;
    vector<ll> arr(n+1);
    fori(1,n+1) cin>>arr[i];
    ll dp[n+1][n+1];
    for(int i=n;i>=1;i--)
    {
        for(int k=i;k<=n;k++)
        {
            if(i==k) 
                dp[i][k]=0;
            else
            {
                ll s=0;
                for(int p=i;p<=k;p++)
                    s+=arr[p];
                dp[i][k]=LLONG_MAX;
                for(int p=i;p<=k-1;p++)
                    dp[i][k]=min(dp[i][k],dp[i][p]+dp[p+1][k]+s);
            }
        }
    }
    cout<<dp[1][n]<<endl;
    cerr<<"Time elapsed"<<1.0*clock()/CLOCKS_PER_SEC<<"s\n";
    return 0;
}


Measured memory_bytes: 1536
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 10**9 + 7

def precompute(M):
    # 残り M 秒あるとする。
    # dp1：人数
    # dp2：生産開始時刻の総和
    g = M + 10
    dp1 = np.ones(M, np.int64)
    dp2 = np.zeros(M, np.int64)
    while g * (g - 1) // 2 > M:
        g -= 1
    while g >= 1:
        newdp1 = np.ones_like(dp1)
        newdp2 = np.zeros_like(dp2)
        for m in range(2 * g, M):
            newdp1[m] = (newdp1[m - g] + dp1[m - g]) % MOD
            newdp2[m] = (newdp2[m - g] + dp2[m - g] + g * newdp1[m]) % MOD
        g -= 1
        dp1, dp2 = newdp1, newdp2
    return dp1, dp2

def main(NC):
    dp1, dp2 = precompute(100_010)
    N, C = NC[::2], NC[1::2]
    for i in range(len(N)):
        n, c = N[i], C[i]
        q, r = divmod(n, c)
        ans = dp1[q] * n - dp2[q] * c
        print(ans % MOD)

if sys.argv[-1] == 'ONLINE_JUDGE':
    import numba
    from numba.pycc import CC
    i8 = numba.int64
    cc = CC('my_module')

    def cc_export(f, signature):
        cc.export(f.__name__, signature)(f)
        return numba.njit(f)

    precompute = cc_export(precompute, (i8, ))
    main = cc_export(main, (i8[:], ))
    cc.compile()

from my_module import main

NC = np.array(read().split(), np.int64)[1:]

main(NC)

Measured memory_bytes: 39516
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

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

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int x;
    cin >> x;
    for(int i=0;i<=x/100;++i) { // 品物の個数
        if(x - 100 * i <= 5 * i) {
            cout << 1 << endl;
            return 0;
        }
    }

    cout << 0 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <ctime>
#include <map>
#include <iomanip>
using namespace std;

typedef long long ll;

#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
 
long gcd(long long a, long long b){
	if (a%b==0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}
}
 
long lcm(long long a, long long b){
	return a / gcd(a,b) * b;
}
 
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a < b) { a = b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a > b) { a = b; return 1; } return 0; }
 
const ll INF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-10;

string s;
int ans;

int main(){
	cin >> s;

	REP(i,s.length()/2){
		if (s[i] != s[s.length()-1-i]) ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())

if a == b:
    print('YES')
    exit()

if a < b:
    after_a = a + v*t
    after_b = b + w*t
    if after_b - after_a <= 0:
        print('YES')
    else:
        print('NO')

if b < a:
    after_a = a - v*t
    after_b = b - w*t
    if after_b - after_a >= 0:
        print('YES')
    else:
        print('NO')

Measured memory_bytes: 9196
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007

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

    string s1, s2;
    cin >> s1;
    cin >> s2;

    ll curr = 0;
    ll prev = 0;
    ll ans = 0;
    rep(i, 0, n){
        if(s1[i] == s2[i]) curr = 0;
        else curr = 1;


        if(i == 0){
            if(curr == 0){
                ans = 3;
            }else{
                ans = 3 * 2;
                i++;
            }
        }else{
            if(curr == 1){
                if(prev == 0){
                    ans *= 2;
                    ans %= MOD;
                }else{
                    ans *= 3;
                    ans %= MOD;
                }
                i++;
            }
            else if(prev == 0){
                ans *= 2;
                ans %= MOD;
            }
        }
        prev = curr;
    }

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


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

int main() {
    //
    long long num, que;
    long long tmp;
    long long bef, aft;
    long long sum = 0;
    map<long long, long long> m;

    cin >> num;

    for (long long i = 0; i < num; i++) {
        //
        cin >> tmp;
        m[tmp]++;
        sum += tmp;
    }

    cin >> que;

    for (long long i = 0; i < que; i++) {
        //
        cin >> bef >> aft;

        tmp = m[bef];

        if (tmp == 0) {
            cout << sum << endl;
            continue;
        }

        sum -= tmp * bef;
        sum += tmp * aft;
        m[bef] = 0;
        m[aft] += tmp;

        cout << sum << endl;
    }
}

Measured memory_bytes: 9284
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >>n;
int output=100000000;
vector<int>x(n);
for(int i=0;i<n;i++){
cin >> x.at(i);
}
for(int i=0;i<100;i++){
int dis=0;
for(int j=0;j<n;j++){
dis += pow((i+1)-x.at(j),2.0);
}
output = min(output,dis);
}
cout << output <<endl;
}

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

int main(){
 int x, fx;
 cin >> x;
 int n = x;
  
 while(x>0){
   fx += x%10;
   x /= 10;
 }
  
 if(n%fx==0) cout << "Yes" << endl;
 else cout << "No" << endl;
}

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

using ll = long long;

int main() {
    int X;
    cin >> X;
    rep(i, 1e9) {
        X -= i;
        if (X <= 0) {
            cout << i << endl;
            break;
        }
    }
}

Measured memory_bytes: 256
X = int(input())

if X == 1:
    ans = 1
else:
    b = 2
    p = 2
    ans = b ** p
    while b <= X:
        while True:
            tmp = b ** p
            if tmp <= X:
                ans = max(ans, tmp)
                p += 1
            else:
                break
        p = 2
        b += 1

print(ans)


Measured memory_bytes: 2940
N,M=map(int, raw_input().split())
e_list=[]
result=0
m=M

for i in range(N):
    e_list.append(map(int, raw_input().split()))

e_list.sort()

#print N,M,e_list

for i in range(N):
    cost=e_list[i][0]
    mnum=e_list[i][1]
#    print cost,mnum,":",m
    if m == 0:
#        print result
        break
    elif m >= mnum:
        result = result + cost * mnum
        m = m - mnum
    elif m < mnum:
        result = result + cost * m
        m = 0

print result


Measured memory_bytes: 21508