akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int x[5];
    rep(i,5){
        cin>>x[i];
    }
    rep(i,5){
        if(x[i]==0){
            cout<<i+1<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3656
#include <stdio.h>

//prototype
int main(void);

int main(void){

  int i, j;   //count variable
  int height, width;

  while(1){

    scanf("%d", &height); scanf("%d", &width);

    if(height == 0 && width == 0){
      break;    //Exit conditions
    }

    for (i = 1; i <= height; i++) {

        //first row & last row
        if (i == 1 || i == height){

          for (j = 1; j <= width; j++) {
              printf("#");
          }
          
          printf("\n");

        } else {

          //other row
          for (j = 1; j <= width; j++) {

            if (j == 1 || j == width) {
              printf("#");    //first and last
            } else {
              printf(".");    //other
            }
            
          }

          printf("\n");

        }
      }
      
    printf("\n");
    
  }

  return 0;
  
}



Measured memory_bytes: 2028
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<string>
#include<cstring>
#include<time.h>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;


#define repi(i,a,b) for(ll i = (a); i < (b); i++)
#define rep(i, n) for(ll i = 0; i < (n); ++i)


ll MOD = 1000000007;


int main() {
	int N, W;
	cin >> N >> W;
	vector<int> v(N + 1);
	vector<int> w(N + 1);
	v[0] = 0;
	w[0] = 0;
	repi(i, 1, N+1) cin >> v[i] >> w[i];
	vector<vector<int>> dp(N + 1);
	rep(i, N + 1) {
		dp[i].resize(W + 1);
		rep(j, W + 1) dp[i][j] = 0;
	}
	repi(i, 1, N + 1) {
		repi(j,1, W + 1) {
			if (j - w[i] < 0) dp[i][j] = dp[i - 1][j];
			else dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
		}
	}
	cout << dp[N][W] << endl;
	return 0;
}



Measured memory_bytes: 6724
#include<stdio.h>
int main(void) {
	int n, m, l;
	int i, j;
	int ans = 0;

	scanf("%d", &n);
	scanf("%d", &m);

	if (m == 1) {
		ans = 0;
	}
	else {
		ans = n - m;
	}

	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main(void) {
	int a[3][3];
	for (int i(0); i < 3; i++) {
		for (int j(0); j < 3; j++) {
			cin >> a[i][j];
		}
	}
	int n;
	cin >> n;
	int b[10];
	for (int i(0); i < n; i++) {
		cin >> b[i];
	}
	bool flag[3][3];
	for (int i(0); i < 3; i++) {
		for (int j(0); j < 3; j++) {
			flag[i][j] = false;
		}
	}
	for (int num(0); num < n; num++) {
		for (int i(0); i < 3; i++) {
			for (int j(0); j < 3; j++) {
				if (b[num] == a[i][j])flag[i][j] = true;
			}
		}
	}
	bool f(false);
	if (flag[0][0]==true && flag[0][1]==true && flag[0][2]==true) {
		cout << "Yes" << endl;
	}
	else if (flag[1][0] == true && flag[1][1] == true && flag[1][2] == true) {
		cout << "Yes" << endl;
	}
	else if (flag[2][0] == true && flag[2][1] == true && flag[2][2] == true) {
		cout << "Yes" << endl;
	}
	else if (flag[0][0] == true && flag[1][0] == true && flag[2][0] == true) {
		cout << "Yes" << endl;
	}
	else if (flag[0][1] == true && flag[1][1] == true && flag[2][1] == true) {
		cout << "Yes" << endl;
	}
	else if (flag[0][2] == true && flag[1][2] == true && flag[2][2] == true) {
		cout << "Yes" << endl;
	}
	else if (flag[0][0] == true && flag[1][1] == true && flag[2][2] == true) {
		cout << "Yes" << endl;
	}
	else if (flag[0][2] == true && flag[1][1] == true && flag[2][0] == true) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

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

int main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i ,n) cin >> a[i];
    int q; cin >> q;
    rep(i ,q){
        int b , e , k;
        int counter = 0;
        cin >> b >> e >> k;
        int pos = b;
        while( pos != e ){
            if( a[pos] == k ) ++counter;
            ++pos;
        }
        cout << counter << endl;
    }
}


Measured memory_bytes: 3100
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,a,b = inpl()
dl = 1
for i in range(a):
    dl *= n-i
    dl %= mod
for i in range(a):
    dl *= pow(a-i,mod-2,mod)
    dl %= mod
# print(dl)
vv = 1
for i in range(b):
    vv *= n-i
    vv %= mod
for i in range(b):
    vv *= pow(b-i,mod-2,mod)
    vv %= mod
# print(vv)
res = pow(2,n,mod) - dl - vv - 1
print(res%mod)

Measured memory_bytes: 10416
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 read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let n = read::<i64>();
    let h = read::<i64>();
    let w = read::<i64>();
    let ans = (n  - h+1) * (n - w+1);
    println!("{}",ans);
}

Measured memory_bytes: 4352
//Created by Kira

#include<bits/stdc++.h>
using namespace std;

#define IOS cin.sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pii pair<int,int> 
#define pb push_back
#define vi vector<int> 
using ll = long long;

const int mod = 1e9 + 7;

ll pwr(ll a, ll b);
    


set<ll> st;

void rec(ll x){
    if(x > 4e9)return;

    st.insert(x);
    int last = x % 10;
    if(last - 1 >= 0)
        rec(x*10 + last-1);
    rec(x*10 + last);
    if(last + 1 <= 9)
        rec(x*10 + last+1);
}

int main(){
   IOS

   vector<ll> v;

   int n; cin>>n;

   for(int i = 1; i <= 9; i++){
       rec(i);
   }

   for(auto it : st)v.pb(it);

   cout<<v[n-1]<<endl;

    







}

ll pwr(ll a, ll b){
   a %= mod;	//Remove mod if not required
   ll res = 1;
   while(b > 0){
    if(b&1)
        res = res * a % mod;
        a = a * a % mod;
    b >>= 1;
    }

    return res;
}



Measured memory_bytes: 6644
#include <bits/stdc++.h>
using namespace std;
int main(){
	string S,T;
	int Q;
	cin>>S>>Q;
	while(Q--){
		int type;
		cin>>type;
		if(type==1)
			swap(S,T);
		else{
			int f;
			char c;
			cin>>f>>c;
			if(f==1)
				T.push_back(c);
			else
        		S.push_back(c);
		}
	}
	reverse(T.begin(),T.end());
	cout<<T+S<<endl;
	return 0;
}

Measured memory_bytes: 1248
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using pii = pair<int, int>;
using pll = pair<LL, LL>;


int main()
{
    cin.sync_with_stdio(0);

    int N;
    cin >> N;

    vector<int> nrs;
    int max_nr = 0;
    for (int i = 0; i < N; ++i)
    {
        int nr;
        cin >> nr;

        max_nr = max(max_nr, nr);
        nrs.emplace_back(nr);
    }
    
    vector<int> res(N);
    for (int i = 0; (1 << i) <= max_nr; ++i)
    {
        int one_cnt = 0;
        for (const int &nr : nrs)
        {
            one_cnt += !!(nr & (1 << i));
        }

        if (one_cnt % 2)
        {
            for (int j = 0; j < N; ++j)
            {
                res[j] += !(nrs[j] & (1 << i)) * (1 << i);
            }
        }
        else
        {
            for (int j = 0; j < N; ++j)
            {
                res[j] += (nrs[j] & (1 << i));
            }
        }
    }

    for (const int &nr : res)
    {
        cout << nr << " ";
    }
}

Measured memory_bytes: 5064
k, t = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)

C = []
for i in range(t):
    C += [i]*A[i]

from collections import deque
B = deque(C)
L = [-1]*k
for i in range(k):
    if i%2 == 0:
        L[i] = B.popleft()
    else:
        L[i] = B.pop()

ans1 = 0
for i in range(1, k):
    if L[i-1] == L[i]:
        ans1 += 1

B = deque(C)
L = [-1]*k
for i in range(k):
    if i%2 == 0:
        L[i] = B.pop()
    else:
        L[i] = B.popleft()

ans2 = 0
for i in range(1, k):
    if L[i-1] == L[i]:
        ans2 += 1

print(min(ans1, ans2))


Measured memory_bytes: 40048
#include <bits/stdc++.h>
 
using namespace std;
 
const long long MOD=1e9+7;
const double PI=3.14159265359;


int main() {
    
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int h,w;
    cin>>h>>w;
    
    int graph[10][10];
    
    for(int i=0; i<=9; i++){
        for(int j=0; j<=9; j++){
            cin>>graph[i][j];
        }
    }
    /*
    for(int i=0; i<10; i++){
        for(int j=0; j<10; j++){
            cout<<graph[i][j]<<" ";
        }
        cout<<endl;
    }
    */
    
    vector<int> dists(10,MOD);
    dists[1]=0;
    
    
    for(int i=0; i<10; i++){
        for(int j=0; j<10; j++){
            for(int k=0; k<10; k++){
                dists[k]=min(dists[k],dists[j]+graph[k][j]);
            }
        }
    }
    /*
    //cout<<dists[8]<<endl;
    for(int i=0; i<=9; i++){
        cout<<dists[i]<<" ";
    }
    cout<<endl;
    */
    
    int ans=0;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            int x;
            cin>>x;
            if(x!=-1){
                ans+=dists[x];
            }
        }
    }
    
    cout<<ans;
    
    
    return 0;
    
}

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

const long long mod = 1e9 + 7ll;
const int N = 2 * 1e5 + 10;

long long fac[ N ];

long long pw( long long a, long long b ) {
	if ( b == 0ll ) return 1ll;
	long long r = pw( a, b / 2ll );
	r = ( r * r ) % mod;
	if ( b % 2ll ) r = ( a * r ) % mod;
	return r;
}
long long inv( long long x ) {
	return pw( x, mod - 2ll );
}
long long path( long long a, long long b ) {
	long long ans = fac[ a + b ];
	ans = ( ans * inv( fac[ a ] ) ) % mod;
	ans = ( ans * inv( fac[ b ] ) ) % mod;
	return ans;
}
int main ( void ) {

	int h, w, a, b;
	std::cin >> h >> w >> a >> b;

	fac[0] = 1ll;
	for ( int i = 1 ; i < N ; i++ ) {
		fac[i] = ( i * fac[i-1] ) % mod;
	}

	long long ans = 0ll;
	for ( int i = h - a, j = b + 1 ; i > 0 and j <= w ; i--, j++ ) {
		ans += ( path( i - 1, j - 1 ) * path( h - i, w - j ) ) % mod;
	}

	ans = ( ans % mod + mod ) % mod;
	std::cout << ans << std::endl;

	return 0;
}

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

typedef signed long long ll;
const int MX = 1e5 + 5;
int AC[MX], WA[MX];

int main() {
    int n, m, num, cor = 0, inc = 0;
    char verdict[5];
    scanf("%d %d", &n, &m);
    for(int i = 0; i < m; i++) {
        scanf("%d %s", &num, verdict);
        if(verdict[0] == 'A') {
            if(!AC[num]) {
                cor++;
                inc += WA[num];
                AC[num] = 1;
            } 
        } else {
            if(!AC[num]) {
                WA[num]++;
            }
        }
    }
    printf("%d %d\n", cor, inc);
    return 0;
}

Measured memory_bytes: 1024
import sys
readline = sys.stdin.readline

from heapq import heappop as hpp, heappush as hp
inf = 10**9+7
def dijkstra(N, s, Edge):    
    dist = [inf] * N
    dist[s] = 0
    Q = [(0, s)]
    while Q:
        dn, vn = hpp(Q)
        if dn > dist[vn]:
            continue
        for df, vf in Edge[vn]:
            if dn + df < dist[vf]:
                dist[vf] = dn + df
                hp(Q, (dn + df,vf))
    return dist

def compress(L):
    L2 = list(set(L))
    L2.sort()
    C = {v : k for k, v in enumerate(L2)}
    return L2, C


N, M = map(int, readline().split())

Edge = []
VS = set(range(N))
geta = 20
Edge = [tuple(map(int, readline().split())) for _ in range(M)]
for a, b, c in Edge:
    a -= 1
    b -= 1
    VS |= {(c<<geta) | a, (c<<geta) | b}
   
_, Cv = compress(list(VS))

Vnum = len(Cv)

nEdge = [[] for _ in range(Vnum)]

for a, b, c in Edge:
    a -= 1
    b -= 1
    ca = Cv[(c<<geta) | a]
    cb = Cv[(c<<geta) | b]
    nEdge[ca].append((0, cb))
    nEdge[cb].append((0, ca))
    nEdge[a].append((1, ca))
    nEdge[ca].append((0, a))
    nEdge[b].append((1, cb))
    nEdge[cb].append((0, b))

dist = dijkstra(Vnum, 0, nEdge)
if dist[N-1] >= inf:
    dist[N-1] = -1
print(dist[N-1])  

Measured memory_bytes: 224624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<int>;
using Vll = vector<ll>;
using VV = vector<V>;
using VVV = vector<VV>;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << '\n'; return os; }
inline int popcount(const int x) { return __builtin_popcount(x); }
const int INF  = 1<<30;
const ll INFll = 1ll<<62;


int main() {
  int n; cin >> n;
  int N = 1<<n;
  VV xy(2, V(n));
  Vll p(n);
  VVV dst(2, VV(n, V(N, INF)));
  Vll ans(n+1, INFll);
  rep(i, n) cin >> xy[0][i] >> xy[1][i] >> p[i];
  rep(i, 2) rep(S, N) {
    rep(j, n) chmin(dst[i][j][S], abs(xy[i][j]));
    rep(j, n) rep(k, n) if (S>>k&1) chmin(dst[i][j][S], abs(xy[i][j]-xy[i][k]));
  }
  rep(S, N) drep(T, S+1) {
    T &= S;
    ll res = 0;
    rep(i, n) res += p[i] * min(dst[0][i][T], dst[1][i][S^T]);
    chmin(ans[popcount(S)], res);
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 9276
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
int main(){
  ll n,k,a=0;cin>>n>>k;
  ll h[n];
  for(int i=0;i<n;i++){
    cin>>h[i];
  }
  sort(h,h+n);
  for(int i=0;i<n-k;i++){
    a+=h[i];
  }
  cout << a<<endl;
}

Measured memory_bytes: 1792
n=int(input())
tc = 0
hc = 0
for _ in range(0,n):
    t,h = input().split()
    if t > h: tc = tc + 3
    if t < h: hc = hc + 3
    if t == h: 
        tc = tc + 1
        hc = hc + 1
print('{0} {1}'.format(tc, hc))

Measured memory_bytes: 7660
#include<bits/stdc++.h>
using namespace std;
#define li long long
#define gc getchar()
#define pc putchar
li read(){
	li x = 0,y = 0,c = gc;
	while(!isdigit(c)) y = c,c = gc;
	while(isdigit(c)) x = (x << 1) + (x << 3) + (c ^ '0'),c = gc;
	return y == '-' ? -x : x;
}
void print(li q){
	if(q < 0){
		pc('-');
		q = -q;
	}
	if(q >= 10) print(q / 10);
	pc(q % 10 + '0');
}
li s1 = 19260817,s2 = 23333333,s3 = 998244853,srd;
li rd(){
	return srd = (srd * s1 + s2 + rand()) % s3;
}
int n,m;
void file(){
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
}
//const int mo = 998244353;
//const int mo = 1000000007;
char c[200010];
li as;
int main(){
	srand(time(0));rd();
	//file();
	int i,j = 0;
	scanf("%s",c + 1);n = strlen(c + 1);
	for(i = 1;i <= n;++i){
		if(c[i] == 'B') ++j;
		else as += j;
	}
	print(as);
	return 0;
}


Measured memory_bytes: 1020
import java.util.*;

public class Main {    
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
        
        int H = sc.nextInt();
        int W = sc.nextInt();
        
        String str[] = new String[H];
        
        for(int i = 0;i < H;i++){
             str[i] = sc.next();
        }
        
        for(int i = 0;i < H;i++){
            System.out.println(str[i]);
            System.out.println(str[i]);
        }        
        
    }            
}

Measured memory_bytes: 24048
function Main(input) {
  var list = input.split(" ");
  var A = parseInt(list[0]);
  var B = parseInt(list[1]);
  var ans = 0;
  
  ans = Math.max(2*A-1, A+B, 2*B-1);
  
  console.log(ans);
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <stdio.h>
#include <math.h>

int N=0;
int D=0;
int X[10][10];
int c=0;

void dist(int n,int m){
   double d=0;
   for(int i=0;i<D;i++) d=d+(X[n][i]-X[m][i])*(X[n][i]-X[m][i]);
   d=sqrt(d);
   if(ceil(d)==floor(d)) c++;
}

int main(){
   scanf("%d %d",&N,&D);
   for(int i=0;i<N;i++){
      for(int j=0;j<D;j++) scanf("%d",&X[i][j]);
   }
   for(int i=0;i<N;i++){
      for(int j=i+1;j<N;j++){
         dist(i,j);
      }
   }
   printf("%d\n",c);
   
   return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <functional>
#include <cmath>
#include <vector>
#include <set>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cstring>
#include <map>
#include <queue>
using namespace std;



int main()
{
	string s, t;
	cin >> s >> t;
	int ans = 0;
	for (int i = 0; i < s.length(); i++)
		if (s[i] == t[i])
			ans++;
	cout << ans;

}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define REP1(i, n) for(int i=1; i<=(n); i++)
#define RREP1(i, n) for(int i=(n); i>=1; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define out(...) printf(__VA_ARGS__)
#if DEBUG
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...) /* ... */
#endif
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
void _OUT() {}; template<class H, class... T> void _OUT(H &h, T &... t) { cout<<' '<<h; _OUT(t...); };
template<class H, class... T> void _P(H &h, T &... t) { cout<<h; _OUT(t...); };
#define _PN(...) _P(__VA_ARGS__); cout << endl;

void solve();
signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

/*================================*/
#if DEBUG
#define SIZE 55
#else
#define SIZE 55
#endif

int N,A,B;
vector<int> V;

int _com[55][55];

int COM(int n, int k) {
    if (n==0 || k==0 || n==k) return 1;
    if (_com[n][k]) return _com[n][k];
    return _com[n][k] = COM(n-1,k) + COM(n-1,k-1);
}

void solve() {
    cin>>N>>A>>B;
    V.resize(N);
    REP(i,N) {
        cin>>V[i];
    }
    sort(ALL(V));
    reverse(ALL(V));
    double sum = accumulate(V.begin(), V.begin()+A, (double)0);
    double ave = sum/A;
    int v = V[A-1];
    int mii = find(ALL(V),v)-V.begin();
    int num = count(ALL(V),v);
    int ans = 0;
    if (V[0]==v) {
        FOR(c,A,min(B,num)+1) {
            ans += COM(num,c);
        }
    } else {
        ans = COM(num,A-mii);
    }
    printf("%.10f\n%lld\n",ave,ans);
}



Measured memory_bytes: 3764
#include <iostream>
#include <algorithm>
#include <string> 
#include <math.h>
#include <set>
#include <vector>
#define rep(i,n) for(int i=0; i< (int)(n); i++)
using namespace std;


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n,y;
	cin >> n >> y;
	int ans10000 = -1;
	int ans5000 = -1;
	int ans1000 = -1;
	for(int i=0; i<=n; ++i){
		for(int k=0; i+k<=n; ++k){
			int j = n-k-i;
			int total = 10000*i + 5000*k + 1000*j;
			if(total==y){
				ans10000 = i;
				ans5000 = k;
				ans1000 = j;

			}
		}
	}
	cout << ans10000 << " " << ans5000 << " " << ans1000 << "\n";
 } 



Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <functional>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <iomanip>
#include <math.h>
#include <list>
#include <numeric>
using namespace std;

long long combi(long long n, long long k) {
  if (n == k || k == 0)
    return 1;
  else {
    return combi(n - 1, k - 1) + combi(n - 1, k);
  }
}

int main(){    
  long long X,Y,Z;
  cin >> X >> Y >> Z;
 
  cout << Z << " " << X << " " << Y << endl;
  
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int H , W;
	int h, w;
	int ansx, ansy;
	
	scanf("%d",&H);
	scanf("%d",&W);
	scanf("%d",&h);
	scanf("%d",&w);
	ansx = H-h;
	ansy = W-w;
	printf("%d\n",ansx*ansy);
	return 0;
}

Measured memory_bytes: 128
///Atcoder
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000

#define ll long long
#define sc scanf
#define pf printf
//#define pi 2*acos(0.0)

#define ft first
#define se second
#define Max 10001000
#define st(s) s.size();
#define r(input) freopen("input.txt","r",stdin)
#define w(output) freopen("output.txt","w",stdout)
#define maxall(v) *max_element(v.begin(),v.end())
#define minall(v) *min_element(v.begin(),v.end())
#define Sort(v) sort(v.begin(),v.end())
#define un(v) Sort(v), v.erase(unique(v.begin(),v.end()),v.end())
#define cover(a,d) memset(a,d,sizeof(a))

using namespace std;


int main()
{
    ll a,b;
    cin>>a>>b;
    if(a<=8 && b<=8)
        cout<<"Yay!"<<endl;
    else
        cout<<":("<<endl;


    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N ((int)(1e5 + 5))
using namespace std;

char s[N] , t[N];

int ssum[N], tsum[N];

int main()
{
    scanf("%s %s",s,t);
    for(int i = 0; s[i]!='\0'; i++){
        ssum[i+1] = ssum[i]+((s[i]-'A')+1);
    }
    for(int i = 0; s[i]!='\0'; i++){
        tsum[i+1] = tsum[i]+((t[i]-'A')+1);
    }
    int q;
    scanf("%d",&q);
    while(q--){
        int i , j , a, b;
        scanf("%d %d %d %d",&i,&j,&a,&b);
        i--;
        a--;
        if((ssum[j]-ssum[i])%3==(tsum[b]-tsum[a])%3) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

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

int main(){
    string t;
    cin >> t;
    rep(i, (int)(t.size())) {
        if ( t[i] == '?' ) cout << "D";
        else               cout << t[i];
    }
    return 0;
}


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

int main()
{
  int n;
  cin >> n;
  if(n - 1)
  {
    int a, b;
    cin >> a >> b;
    cout << a + b << endl;
  }
  else
  {
    cout << "Hello World" << endl;
  }
  return 0;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define x first
#define y second
#define mod 1e9+7
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rof(i,a,b) for(ll i=a;i>b;i--)
//cf dont use unordered map. use simply map<... , ... > m;

//They are Iterator minus v.begin() krna //lower_bound(v.begin(),v.end(),x)-v.begin()  //upper_bound(v.begin(),v.end(),x)-v.begin()
// lower bound tells greater than or equal to // upper bound tells strictly greater than
//int a[1001][1001] //aise global me hi// ll lcm(ll a, ll b){ return a / __gcd(a, b) * b; }
//memset can initialize to 0 or -1 ONLY //memset(str, 't', sizeof(str)); // string //memset(a, 0, sizeof(a));  //1D array    // memset(a,0,sizeof(a[0][0])*n*n); //2D array
// set.insert(),find() //for(auto it=set.begin();....) cout<<*it;   // sort(v.begin(),v.end(),compare)

void solve()
{
    ll n,s=0;cin>>n;
f(i,1,n+1)
{
	if(i%3!=0&&i%5!=0) s+=i;
}
cout<<s;
}


int main()
{

ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll t=1;
  //  cin>>t;
    while(t--)
    {
     solve();
    }
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
 
#define int long long int
#define ld long double
#define mod 1000000007 
#define pii pair<int,int>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define forn(i,s, e) for (int i = s; i <= e; i++)
#define fornd(i,s, e) for (int i = s ; i >= e; i--)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define print(x) for(auto el: x) cout<<el<<" ";cout<<"\n"
#define PSET(x,y) fixed<<setprecision(y)<<x
// #define bits(x) __builtin_popcount(x)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

 

 
template <typename T> 
void swap(T& a, T& b){
    T temp = a;
    a = b;
    b = temp;
}

const int N = 100005; 

int dp[401][401];

void solve(){
    
    int n;
    cin>>n;
    int* arr = new int [n+1]();

    forn(i,0,n-1)
        cin>>arr[i];

    int* ca = new int[n+1]();
    ca[n-1] = arr[n-1];
    for(int i=n-2;i>=0;i--){
        ca[i] = arr[i]+ca[i+1];
    }


    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            dp[i][j] = 1LL*1e18;
        }
    }
    
    for(int i=0;i<n;i++)
        dp[i][i] = 0;

    for(int i=n-2;i>=0;i--){
        for(int j = i+1; j<n;j++){
            for(int k=i;k<j;k++){
                dp[i][j] = min(dp[i][j], dp[i][k]+dp[k+1][j]+ ca[i]-ca[j+1] );
            }
        }
    }

    cout<<dp[0][n-1]<<endl;

}
 
int32_t main()
{
    fast;
    // int t;
    // cin>>t;
    // for(int y=1;y<=t;y++)
    {
        // cout<<"Case #"<<y<<": ";
        solve();
    }
    return 0;
} 

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

int main() {

  int H, W;
  cin >> H >> W;

  vector<vector<int>> a(H,vector<int>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> a[i][j];
    }
  }
  
  int add = 0;
  int x = -1;
  int y = -1;
  vector<string> answer;

  for (int i = 0; i < H; i++) {
    if (i % 2 == 0) {
      for (int j = 0; j < W; j++) {
        if (add == 1) {
          a[i][j] += add;
          string ans = to_string(y) + " " + to_string(x) + " " + to_string(i + 1) + " " + to_string(j + 1);
          answer.push_back(ans);
        }
        if (a[i][j] % 2 == 1) {
          if (i != H - 1 || j != W - 1) {
            add = 1;
            a[i][j]--;
            x = j + 1;
            y = i + 1; 
          }
        } else {
          add = 0;
        }
      }
    } else {
      for (int j = W - 1; 0 <= j; j--) {
        if (add == 1) {
          a[i][j] += add;
          string ans = to_string(y) + " " + to_string(x) + " " + to_string(i + 1) + " " + to_string(j + 1);
          answer.push_back(ans);
        }
        if (a[i][j] % 2 == 1) {
          if (i != H - 1 || j != 0) {
            add = 1;
            a[i][j]--;
            x = j + 1;
            y = i + 1;
          }
        } else {
          add = 0;
        }
      }
    }
  }

  cout << answer.size() << endl;
  for (int i = 0; i < answer.size(); i++) {
    cout << answer[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 11892
#include <stdio.h>
#include <vector>
#include <iostream>

typedef struct _Card {
    char mark;
    int value;
}Card;

void BubbleSort(std::vector<Card> &c, int n)
{
    for (int i = 0; i < n; i++) {
        for (int j = n - 1; j > i; j--) {
            if (c[j].value < c[j - 1].value) {
                Card tmp = c[j];
                c[j] = c[j - 1];
                c[j - 1] = tmp;
            }
        }
    }
}

void SelectionSort(std::vector<Card> &c, int n)
{
    for (int i = 0; i < n; i++) {
        int minj = i;
        for (int j = i; j < n; j++) {
            if (c[j].value < c[minj].value) {
                minj = j;
            }
        }

        Card tmp = c[i];
        c[i] = c[minj];
        c[minj] = tmp;
    }
}

void Print(std::vector<Card> &c, int n)
{
    std::cout << c[0].mark << c[0].value;
    for (int i = 1; i < n; i++) {
        std::cout << " ";
        std::cout << c[i].mark << c[i].value;
    }
    std::cout << "\n";
}

int main(void)
{
    int n = 0;
    std::cin >> n;

    std::vector<Card> c(n);
    for (int i = 0; i < n; i++) {
        std::cin >> c[i].mark >> c[i].value;
    }

    std::vector<Card> bubbleValue = c;
    std::vector<Card> selectValue = c;
    

    // bubbleSort
    BubbleSort(bubbleValue, n);
    Print(bubbleValue, n);
    std::cout << "Stable\n";

    SelectionSort(selectValue, n);
    Print(selectValue, n);

    bool isStable = true;
    for (int i = 0; i < n; i++) {
        if (bubbleValue[i].mark != selectValue[i].mark) {
            isStable = false;
            break;
        }
    }
    if (isStable) {
        std::cout << "Stable\n";
    } else {
        std::cout << "Not stable\n";
    }

    return 0;
}


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

void findComb(int n, int y, int& i, int& j, int& k) {
  for (i = 0; i <= n; ++i) {
    for (j = 0; j + i <= n; ++j) {
      k = n - i - j;
      int total = 10000 * i + 5000 * j + 1000 * k;
      if (total == y) {
        return;
      }
    }
  }
  i = j = k = -1;
}

int main() {
  int n, y;
  cin >> n >> y;

  int i, j, k;
  findComb(n, y, i, j, k);
  cout << i << " " << j << " " << k << endl;
}


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

public class Main {

	public static void print_ary(int[] a) {
		for (int i = 0; i < a.length; i++) {
			System.out.print(a[i]);
			if (i != a.length - 1) {
				System.out.print(" ");
			}
		}
		System.out.print("\n");
	}

	public static void my_insertion_sort(int[] a) {
		print_ary(a);
		for (int i = 1; i < a.length; i++) {
			int key = a[i];
			int j = i - 1;
			while (j >= 0 && a[j] > key) {
				a[j+1] = a[j];
				j--;
			}
			a[j+1] = key;
			print_ary(a);
		}
	}

	public static void main(String[] args) {
		// Collect input
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = s.nextInt();
		}
		// Sort
		my_insertion_sort(a);
	}

}



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

namespace atcorder_BeginnerContest_117
{
    class Program
    {
        static void Main(string[] args)
        {
            int cnt = int.Parse(Console.ReadLine());
            int[] dataArr = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            dataArr = dataArr.OrderByDescending(x => x).ToArray();

            int sum = 0;
            for (int i = 1; i < cnt ; i++)
            {
                sum += dataArr[i];
            }

            string ret = "No";
            if (dataArr[0] < sum)
            {
                ret = "Yes";
            }

            Console.WriteLine(ret);
        }
    }
}


Measured memory_bytes: 13396
def dist(p,q):
    return abs(p[0]-q[0]) + abs(p[1]-q[1])

def main():
    H,W,D = map(int,input().split())

    A = []
    for i in range(H):
        A.append(list(map(int,input().split())))

    pos = [(-1,-1) for i in range(H*W)]
    for i in range(H):
        for j in range(W):
            A[i][j] -= 1
            pos[A[i][j]] = (i,j)


    pre = [[0 for j in range((2*H*W)//D)  ] for i in range(D)]
    for i in range(D,H*W):
        pre[i%D][i//D] = pre[i%D][i//D - 1] + dist(pos[i], pos[i-D])

    Q = int(input())
    for _ in range(Q):
        L,R = map(int,input().split())
        L -= 1
        R -= 1

        v = pre[L%D]
        print(v[R//D] - v[L//D])

if __name__ == '__main__':
    main()


Measured memory_bytes: 24244
using System;

namespace AtCoder.ABC._101
{
    class b
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Trim();
            var N = int.Parse(line);
            var t = N;
            var sum = 0;
            while(t > 0)
            {
                sum += t % 10;
                t /= 10;
            }
            Console.WriteLine(N % sum == 0 ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 11092
#!/usr/bin/env python

import sys
import math
import itertools as it
from collections import deque

sys.setrecursionlimit(10000000)

MOD = 10 ** 9 + 7
n, k = map(int, raw_input().split())

def fact(N):
    if N <= 1:
        return 1
    return fact(N - 1) * N

if n < k:
    print 0
else:
    print (fact(n - 1) / fact(n - k) / fact(k - 1)) % MOD


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

int main() {
    int n,m;
    cin >> n >> m;
    vector<int> b(m);

    int k;
    int x;
    for (int i = 0; i < n; i++) {
        cin >> k;
        for (int j = 0; j < k; j++) {
            cin >> x;
            b.at(x - 1)++;
        }
    }

    int answer = 0;
    for (int i = 0; i < m; i++) {
        if (b.at(i) == n) answer++;
    }
    cout << answer << endl;
}


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

int main(void) {
  int n,Lmax=-1,sum=0;
  cin>>n;
  int l[n];
  for(int i=0;i<n;i++){
    cin>>l[i];
    sum+=l[i];
    if(Lmax<l[i]){
      Lmax=l[i];
    }
  }
  
  if(sum>2*Lmax) cout<<"Yes\n";
  else cout<<"No\n";
  return 0;
}


Measured memory_bytes: 384
/*
	Solved!
	Time: 05:23:26 PM
	Date: 05-04-2020
*/
#include <bits/stdc++.h>
using namespace std;
 
typedef unsigned long long  ll;
typedef vector<int>         vi;
typedef vector<ll>          vll;

#define ff                  first
#define sf                  scanf
#define pf                  printf
#define ss                  second
#define ppb                 pop_back
#define pb                  push_back
#define MP                  make_pair
#define MAXN                5000005
#define MOD                 100000007
#define inf                 0x3f3f3f3f
#define PI                  (2.0*acos(0.0))
#define INF                 0x3f3f3f3f3f3f3f3f
#define rev(v)              reverse(all(v))
#define all(v)              v.begin(), v.end()
#define __lcm(x, y)         (x * y) / __gcd(x, y)
#define FOR(i, x, y)        for(int i = x; i < y; i++)
#define RFOR(i, x, y)       for(int i = x; i >= y; i--)
#define MEM(arr, val)       memset(arr, val, sizeof(arr));
#define unq(v)              (v).resize(unique(all(v)) - v.begin())
#define READ()              freopen("input.txt", "r", stdin)
#define WRITE()             freopen("output.txt", "w", stdout)
#define si(n)               scanf("%d", &n)
#define sl(n)               scanf("%lld", &n)
#define sii(a, b)           scanf("%d %d", &a, &b)
#define sll(a, b)           scanf("%lld %lld", &a, &b)
#define siii(a, b, c)       scanf("%d %d %d", &a, &b, &c)
#define slll(a, b, c)       scanf("%lld %lld %lld", &a, &b, &c)
#define siiii(a, b, c, d)   scanf("%d %d %d %d", &a, &b, &c, &d)
#define sllll(a, b, c, d)   scanf("%lld %lld %lld %lld", &a, &b, &c, &d)
#define vout(v)             for(int i = 0; i < v.size(); i++) {cout << v[i]; if(i < v.size() - 1) cout << ' '; else cout << endl;}

int main(){
    /*#ifndef ONLINE_JUDGE
        double start = clock(); READ(); WRITE();
    #endif*/
        int n, ans = 0; si(n);
        vi v(n);
        FOR(i, 0, n) si(v[i]);
        FOR(i, 0, n){
        	vi tmp;
        	FOR(j, i, n) {
        		tmp.pb(v[j]);
        		if(tmp.size() == 3) break;
        	}
        	sort(all(tmp));
        	if(v[i + 1] == tmp[1] && tmp.size() == 3) ++ans;
        }
        cout << ans << endl;

    /*#ifndef ONLINE_JUDGE
        printf("\n>>Runtime: %.10fs\n", (double)(clock() - start) / CLOCKS_PER_SEC);
    #endif*/

    return 0;
}

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

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

    int n;
    cin >> n;
    vector<int> a(n), s(n);
    rep(i, n)
    {
        cin >> a[i];
        s[i] = a[i];
        if (i != 0)
            s[i] += s[i - 1];
    }
    int ans = 1e9;
    rep(i, n - 1) ans = min(ans, abs(s[n - 1] - 2 * s[i]));

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IO std::ios::sync_with_stdio(false),cin.tie(0)

using namespace std;

int fun(int x, int y, int z) {
	return x*x + y*y + z *z + x *z + y *z + x *y;
}

int a[10001];
int main() {
	int n;
	memset(a,0,sizeof(a));
	cin >> n;
	for(int j = 1; j <= 100; j++) {
			for(int k = 1; k <= 100; k++) {
				for(int l = 1; l <= 100; l++) {
					int t = fun(j,k,l);
					if(t <= 10000) a[t]++;
				}
			}
		}
		
	for(int i= 1; i <= n; i++) cout << a[i] << "\n";
	return 0;
}


Measured memory_bytes: 3668
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=150;
//ここまでテンプレ
vll stov(string S){
	vll v;
	string temp;
	for(int i=0;i<S.length();i++){
		if(S[i]<'0' || '9'<S[i]){
			if(temp.length())
				v.pb(stoi(temp));
			v.pb(S[i]+10000000000LL);
			temp.clear();
		}
		else
			temp+=S[i];
	}
	if(temp.length())
		v.pb(stoi(temp));
	return v;
}
int main(){
	int N;
	cin>>N;
	string S;
	cin>>S;
	vll v=stov(S);
	for(int i=0;i<N;i++){
		string T;
		cin>>T;
		vll w=stov(T);
		if(v<=w)
			cout<<"+"<<endl;
		else
			cout<<"-"<<endl;
	}
	return 0;
}



Measured memory_bytes: 3160
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# import numpy as np
sys.setrecursionlimit(int(pow(10,6)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]

# @lru_cache(None)
def printString(n): 
  
    # To store result (Excel column name) 
    string = ["\0"] * 50
  
    # To store current index in str which is result 
    i = 0
  
    while n > 0: 
        # Find remainder 
        rem = n % 26
  
        # if remainder is 0, then a  
        # 'Z' must be there in output 
        if rem == 0: 
            string[i] = 'z'
            i += 1
            n = (n // 26) - 1
        else: 
            string[i] = chr((rem - 1) + ord('a')) 
            i += 1
            n = n // 26
    string[i] = '\0'
    ans=[]
    for ele in string:
        if ele.isalpha():
            ans.append(ele)
    string=ans
    # Reverse the string and print result 
    string = string[::-1] 
    print( "".join(string)) 
n=l()[0]
printString(n)







Measured memory_bytes: 10644
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define a first
#define b second
using namespace std;
typedef pair<ll, ll> line;
const int N = 2e5 + 5;
ll n, c, h[N], dp[N];

ll val(line u, ll x) { return u.a * x + u.b; }
ld giaoX(line u, line v) { return (ld)(v.b - u.b) / (u.a - v.a); }
struct conVex
{
    vector<line> dq;
    void add(line u)
    {
        while (dq.size() >= 2 && giaoX(u, dq[dq.size() - 1]) <= giaoX(u, dq[dq.size() - 2]))
            dq.pop_back();
        dq.emplace_back(u);
    }
    ll query(ll x)
    {
        int d = 0, c = dq.size() - 1, mid;
        while (d < c)
        {
            mid = (d + c) >> 1;
            if (val(dq[mid], x) <= val(dq[mid + 1], x))
                c = mid;
            else
                d = mid + 1;
        }
        return val(dq[d], x);
    }
} T;

int main()
{
    //freopen("z.inp", "r", stdin);
    ios::sync_with_stdio(0), cin.tie(0);
    cin >> n >> c;
    for (int i = 1; i <= n; i++)
        cin >> h[i];
    //dp[i] = min(dpj + (hj - hi)^2 + c) = dpj + hj^2 - 2hjhi + hi^2 + c
    //dp[i] = min(-2hj*hi + dpj + hj^2) + hi^2 + c
    dp[1] = 0;
    T.add({-2 * h[1], h[1] * h[1]});
    for (int i = 2; i <= n; i++)
    {
        dp[i] = T.query(h[i]) + h[i] * h[i] + c;
        T.add({-2 * h[i], dp[i] + h[i] * h[i]});
    }
    cout << dp[n];
    return 0;
}

Measured memory_bytes: 10404
// D.

#include <iostream>
#include <algorithm>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>

using namespace std;
typedef long long LL;

LL check(LL b, LL n) {
	LL c = 0;
	while (n) {
		c += n % b;
		n /= b;
	}
	return c;
}

int main(int argc, char *argv[]) {
	LL n, s;
	cin >> n >> s;
	LL ans = 1LL << 60;
	if (s == 1LL) {
		ans = n;
	}
	if (s == n) {
		ans = n + 1;
	}
	LL m = sqrt(n);
	for (LL b = 2; b <= m; ++b) {
		if (check(b, n) == s) {
			ans = min(ans, b);
		}
	}
	for (LL p = 1; p < m; ++p) {
		LL b = (n - s) / p + 1;
		LL q = s - p;
		if (b >= m && q >= 0 && q < b && n == (p * b + q)) {
			ans = min(ans, b);
		}
	}
	cout << (ans == (1LL << 60) ? -1 : ans) << endl;
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map> 
#include <unordered_set>
#include <functional>
#include <bitset>

using namespace std;

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

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

bool used[110000];
int isOdd[110000];
vector<int> E[110000];

bool func(int pos, bool flag){
	//cout << pos << endl;
	if(isOdd[pos] != 0){
		//cout << "return" << endl;
		return (isOdd[pos] == 1) ^ flag;
	}
	if(flag){
		isOdd[pos] = 1;
	}else{
		isOdd[pos] = -1;
	}
	bool ret = false;
	for(int to : E[pos]){
		//cout << pos << " to " << to << endl;
		bool res = func(to, !flag);
		ret = (ret || res);
	}
	return ret;
}

int main(){
	int N, M;
	cin >> N >> M;
	for(int i = 0; i < M; i++){
		int u, v;
		cin >> u >> v;
		E[u].push_back(v);
		E[v].push_back(u);
		used[u] = true;
		used[v] = true;
	}
	long long int ans = 0;
	long long int cnt1 = 0, cnt2 = 0, cnt3 = 0;
	for(int i = 1; i <= N; i++){
		if(!used[i]){
			cnt1 += 1;
		}else if(isOdd[i] == 0){
			bool ret = func(i, true);
			//cout << i << " : pos" << endl;
			if(ret){
				cnt2 += 1;
			}else{
				cnt3 += 1;
			}
		}
	}
	//cout << cnt1 << " " << cnt2 << " " << cnt3 << endl;
	ans += cnt1 * N * 2 - cnt1 * cnt1;
	ans += (cnt2 + cnt3) * (cnt2 + cnt3);
	ans += cnt3 * cnt3;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 10240
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    M = I()
    dc = [LI() for _ in range(M)]

    s = sum([i[0]*i[1] for i in dc])
    print((sum([i[1] for i in dc])-1)+(s-1)//9)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 41452
def resolve():
    n = int(input())
    name = []
    while n > 0:
        c = n % 26
        n //= 26
        if c == 0:
            name.append('z')
            n -= 1
        else:
            name.append(chr(c + 96))

    name.reverse()
    ans = ''.join(name)
    print(ans)

resolve()

Measured memory_bytes: 9168
fun main (args: Array<String>) {
	val (num1, num2, num3) = readLine()!!.split(" ").map(String::toInt)
	
	var num : Int
	var calc : Int
	var result : Int = 0
	var total : Int = 0
	
	for (i in 1..num1) {
		num = i
		
		while (num > 0) {
			calc = num % 10
			result += calc
			num = num / 10
			
		}
		
		if (result >= num2 && result <= num3) {
			total += i
			
		}
		result = 0
		
	}
	
	println("${total}")
	
}

Measured memory_bytes: 37936
import sys
import numpy as np
input = sys.stdin.readline

n=int(input())
v=np.array(list(map(int,input().split())))
c=np.array(list(map(int,input().split())))
s = (v-c)
ans =0
for ss in s:
    ans += ss*(ss>0)
print(ans)


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

int main() {
  int N, B,sum,c1,c2,c3,c4,c5,LA;
  cin >> N;
  int A[N];
  B=0;
  for(int i=0;i<N;i++){
  	cin >> A[i];
    }
 for(int j=0;;j++) {
  for(int i=0;i<N;i++){
    if(A[i]%2==1){
    	cout<<j<<endl;
        B=1;
      break;
    }
    A[i] /= 2;
    
   }
   if(B==1){
   break;
   }
  }
}

Measured memory_bytes: 256
n = int(input())
cnt = {c:0 for c in 'MARCH'} # how many 

for i in range(n):
    s = input()
    if s[0] in 'MARCH':
        cnt[s[0]] += 1

# all possible combinations
ret = cnt['M']*cnt['A']* (cnt['R'] + cnt['C'] + cnt['H']) \
      + cnt['M']*cnt['R']* (cnt['C'] + cnt['H'])  + cnt['M']*cnt['C']*cnt['H'] \
      + cnt['A']*cnt['R']* (cnt['C'] + cnt['H'])  + cnt['A']*cnt['C']*cnt['H'] \
      + cnt['R']*cnt['C']*cnt['H']
    
print(ret)

Measured memory_bytes: 3188
# -*- coding: utf-8 -*-

W, a, b = map(int, input().split())

if (a + W) < b: # bが右側にいるか判定
    print(b - (a + W))
elif (b + W) < a: # bが左側にいるか判定
    print(a - (b + W))
else:
    print(0)

Measured memory_bytes: 9068
n = int(input()) #問題数
a,b = map(int,(input().split())) 
p = list(map(int,(input().split()))) #点数

x,y,z = 0,0,0
for i in p:
    if i <= a:
        x += 1
    elif a + 1 <= i <= b:
        y += 1
    else:
        z += 1


print(min(x,y,z))

    

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		String s = sc.next();
		sc.close();

		if (s.length() <= k) {
			System.out.println(s);
		} else {
			System.out.println(s.substring(0, k) + "...");
		}
	}
}


Measured memory_bytes: 38632
#include<cstdio>
#include<string>
#include<cstring>
#include<utility>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<algorithm>
#include<vector>
#include<iostream>
#define ll long long
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define inf 0x7fffffff
using namespace std;
int a[200];
int main()
{
	int i,j,k,n,mi,x=0,y=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		y+=a[i];
	}
	mi=y;
	for(i=0;i<n;i++)
	{
		x+=a[i];
		y-=a[i];
		mi=min(abs(x-y),mi);
	}
	printf("%d",mi);
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define re register
const int mod=998244353;
int f[310][310][310],g[310][310][310];
char ss[310];
int main()
{
	re int n;
	scanf("%s",ss+1);
	n=strlen(ss+1);
	g[0][0][0]=1;
	for(re int i=1;i<=n;i++)
	{
		for(re int j=0;j<=n;j++)
			for(re int k=0;k<=n;k++)
			{
				if(ss[i]=='0'&&j)g[i][j][k]|=g[i-1][j-1][k+1];
				if(ss[i]=='1'&&k)g[i][j][k]|=g[i-1][j+1][k-1];
				g[i][j][k]|=g[i-1][j][k];
				if(i>=2)
				{
					if((ss[i]=='0'||ss[i-1]=='0')&&j)g[i][j][k]|=g[i-2][j-1][k];
					if((ss[i]=='1'||ss[i-1]=='1')&&k)g[i][j][k]|=g[i-2][j][k-1];
				}
			}
	}
	for(re int i=0;i<=n;i++)
	{
		if(ss[n]=='0')f[n][0][i]=1;
		else f[n][i][0]=1;
	}
	for(re int i=n-1;i>=0;i--)
	{
		for(re int j=0;j<=n;j++)
		{
			for(re int k=0;k<=n;k++)
			{
				f[i][j][k]=f[i+1][j][k];
				if(ss[i]=='0'&&k)f[i][j][k]=(f[i][j][k]+f[i][j][k-1])%mod;
				if(ss[i]=='1'&&j)f[i][j][k]=(f[i][j][k]+f[i][j-1][k])%mod;
			}
		}
	}
	re int ans=0;
	for(re int i=0;i<=n;i++)
		for(re int j=0;j<=n;j++)
			for(re int k=0;k<=n;k++)
			if(i!=n||j||k){
				ans=(ans+g[i][j][k]*f[i][j][k])%mod;
				//if(g[i][j][k])printf("***%d %d %d %d %d\n",i,j,k,f[i][j][k],ans);
			}
	printf("%d\n",ans);
}

Measured memory_bytes: 225112