akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-

N,K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))

answer = max(C)
for i in range(N):
  pos = P[i] - 1
  score = C[pos]
  score_list = [score]
  step = 1
  while pos!=i and step<K:
    pos = P[pos] - 1
    score += C[pos]
    score_list.append(score)
    step += 1
  score_max = max(score_list)
  if score_list[-1]>0 and step<K:
    loop = K//step
    amari = K%step
    for j in range(step):
      if j<amari:
        score_max = max(score_max, score_list[-1]*loop+score_list[j])
      else:
        score_max = max(score_max, score_list[-1]*(loop-1)+score_list[j])
  answer = max(answer,score_max)

print(answer)

Measured memory_bytes: 81280
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    int ans;
    ans = max({a[0], a[1], a[2]}) - min({a[0], a[1], a[2]}); 
    cout << ans << endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  int x;
  cin >> x;
  int sum = 0;
  rep2(i, 1, x+1){
    sum += i;
    if(sum >= x){
      cout << i << endl;
      return 0;
    }
  }
  return 1;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int N;
    long long ans = 0;
    cin >> N;
    int C[N][N];
    for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) cin >> C[i][j];
    for (int i = 0; i < N; i++) for (int j = i+1; j < N; j++) ans += min(C[i][j],C[j][i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
using namespace std;
int main() {
    int n,cnt=0,ans=0,sum=0,o=0;
    string s;
    char a;
    int b;
    cin>>n>>b;
    if(n%2==0||b%2==0){
        cout<<"No"<<endl;
    }
    else cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
int main(){
   
    int a,b;
    char op;
    cin>>a>>op>>b;
    
    if(op=='+'){
        cout<<a+b<<endl;
    }else{
        cout<<a-b<<endl;
    }
    
    
    return 0;
   
}






Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

long long n, a, b;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> a >> b;
    long long ans = 1e18 + 1;
    if (abs(a - b) % 2 == 0) {
        long long tmp = abs(a - b) / 2;
        ans = min(ans, tmp);
    }
    else {
        long long c = a, d = b;
        long long tmp = min(c, d) - 1;
        c -= tmp; d -= tmp;
        if (abs(c - d) % 2) {
            tmp++;
            tmp += abs(c - d) / 2;
            ans = min(ans, tmp);
        }
        else {
            tmp += abs(c - d) / 2;
            ans = min(ans, tmp);
        }
        c = a; d = b;
        tmp = min(n - c, n - d);
        c += tmp; d += tmp;
        if (abs(c - d) % 2) {
            tmp++;
            tmp += abs(c - d) / 2;
            ans = min(ans, tmp);
        }
        else {
            tmp += abs(c - d) / 2;
            ans = min(ans, tmp);
        }
    }
    cout << ans << E;
    //system("pause");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define M 1000000007
#define pb push_back
#define boost ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define NAYAN freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
signed main()
{
    boost
    
    int n,k;
    cin >> n >> k;
    int a[n];
    int i;
    for(i=0;i<n;i++)
    {
        cin >> a[i];
    }
    cout << ceil(double(n-1)/(k-1));
}











Measured memory_bytes: 1024
//creator :Harjot Singh	

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define vi vector<int> 
#define vll vector<long long > 
#define for(i,a,b) for(int i=a;i<=b;i++)
#define vii vector<int,int> 
#define ll long long 
const int mod=1e9+7;
int main()
{
     int n,k;

     cin>>n>>k;

     ll arr[n+1];
     for(i,0,n)
     	cin>>arr[i];

     ll dp[n+1][k+1];
     
     for(i,0,k)
     	dp[1][i]=i>arr[0]?0:1;

     for(i,2,n)
     {
     	for(j,0,k)
     	{
     		if(j==0)
     			dp[i][j]=dp[i-1][j];
     		else
     		dp[i][j]=(mod+dp[i][j-1]+dp[i-1][j]-(j-1-arr[i-1]>=0? dp[i-1][j-1-arr[i-1]]:0))%mod;

     	}
     }

     cout<<dp[n][k];


   

	return 0;
}

Measured memory_bytes: 78336
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <set>
#include <cmath>
#include <cstring>
#include <stdio.h>
#include <string.h>
#include <sstream>
#include <stdlib.h>
#include <vector>
#include <iomanip>
#include <ctime>
#include <deque>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdlib>
#include <cassert>

#define nl "\n"
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define p_un(a) ((void)a)
#define p_st(a) string(a)
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define naj ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define NL cout << endl;
#define sqr(x) (sqrt(x) * 1LL)
#define pcnt(i) __builtin_popcount(i)
#define lcm(a,b) (a * b) / __gcd(a, b)
#define E 2.718281828459045
#define PI 3.141592653589793
#define up_b upper_bound
#define low_b lower_bound
#define FILE_NAME "A"
#define show(x) cout << (#x) << ": " << x << endl

using namespace std;

typedef long long llong;
typedef long double ldouble;
typedef unsigned long long ullong;
typedef vector <llong> vl;
typedef vector <bool> vb;
typedef vector <char> vc;
typedef vector <int> vi;
typedef vector <string> vs;
typedef pair <llong, llong> pll;
typedef map <llong, llong> mll;
typedef set <llong> sl;
typedef set <char> sc;
typedef map <string, llong> msl;
typedef map <string, bool> msb;
typedef map <char, llong> mcl;
typedef map <string, string> mss;

const llong MXN = 1e6 + 1;
const llong MOD = 1e9 + 7;
const llong INF = 1e18;
const ldouble EPS = 1e-9;

#define int int64_t

//int dx[]= {1,0,-1,0}; int dy[]= {0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1}; int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2}; int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={-1,-1,+0,+1,+1,+0}; int dy[]={-1,+1,+2,+1,-1,-2}; //Hexagonal Direction

int n;
double cost = 0;

signed main() {

    naj;
#ifdef LOL
    freopen(FILE_NAME".in", "r", stdin);
    freopen(FILE_NAME".out", "w", stdout);
#endif
    cin >> n;
    double BTC = 380000.0;
    for(int i = 1; i <= n; i++) {
        double x;
        string s;
        cin >> x >> s;
        cost += (s == "JPY" ? x : x * BTC);
    }
    cout << fixed << setprecision(10) << cost;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N,M;
    int Acity[60],Bcity[60];
    cin>>N>>M;
    for(int i=0;i<M;i++){
        cin>>Acity[i]>>Bcity[i];
    }
    
    
    int cnt[60];
    for(int i=0;i<60;i++){
        cnt[i]=0;
    }
    for(int j=1;j<=N;j++){
        for(int i=0;i<M;i++){
            if(j==Acity[i]){
                cnt[j-1]++;
            }
            if(j==Bcity[i]){
                cnt[j-1]++;
            }
            
        }
    }
    
    for(int i=0;i<N;i++){
        cout<<cnt[i]<<endl;
    }
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
vector<vector<int> >vec;
int n;
vector<int>d;
void bfs(int s) {
	queue<int>q;
	q.push(s);
	d[s] = 0;
	while (!q.empty()) {
		int u = q.front(); q.pop();
		rep(v, 0, vec[u].size()) {
			if (d[vec[u][v]] != INF)continue;
			d[vec[u][v]] = d[u] + 1;
			q.push(vec[u][v]);
		}
	}
	rep(i, 0, n) {
		cout << i + 1 << " " << ((d[i]==INF)?-1:d[i]) << endl;
	}
}
signed main() {
	cin >> n; vec = vector<vector<int> >(n); d = vector<int>(n, INF);
	rep(i, 0, n) {
		int u, k; cin >> u >> k; u--;
		rep(j, 0, k) {
			int v; cin >> v; v--;
			vec[u].push_back(v);
		}
	}
	bfs(0);

	return 0;
}

Measured memory_bytes: 3148
#!/usr/bin/env ruby

N, M, K = gets.chomp.split.map(&:to_i)
A = [0].concat(gets.chomp.split.map(&:to_i))
B = [0].concat(gets.chomp.split.map(&:to_i))

1.upto(N) do |i|
  A[i] = A[i-1] + A[i]
end

1.upto(M) do |i|
  B[i] = B[i-1] + B[i]
end

n = N
m = M
max = 0

0.upto(n) do |i|
  a = A[i]

  break if a > K

  m.downto(0) do |j|
    if a + B[j] <= K
      m = j
      v = i + j
      max = v if max <= v
      break
    end
  end
end

puts max


Measured memory_bytes: 50780
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define int long long
using namespace std;
signed main() {
    int n, a, b;
    cin >> n >> a >> b;
    int amari;
    amari = n % (a + b);
    if(amari > a) amari = a;
    cout << n / (a + b) * a + amari;
    return 0;
}

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

using namespace std;

int dx[27], dy[27], dz[27];

int main(){
	ios_base::sync_with_stdio(false);
	for(int i = -1, p = 0; i <= 1; ++i){
		for(int j = -1; j <= 1; ++j){
			for(int k = -1; k <= 1; ++k){
				if(i == 0 && j == 0 && k == 0){ continue; }
				dx[p] = i;
				dy[p] = j;
				dz[p] = k;
				++p;
			}
		}
	}
	while(true){
		int n, m, p;
		cin >> n >> m >> p;
		if(n == 0 && m == 0 && p == 0){ break; }
		vector<int> x(p), y(p);
		for(int i = 0; i < p; ++i){
			cin >> x[i] >> y[i];
			--x[i]; --y[i];
		}
		vector< vector< vector<int> > > c(
			n, vector< vector<int> >(n, vector<int>(n)));
		vector< vector<int> > h(n, vector<int>(n));
		int answer = 0, elapsed = 0;
		for(int i = 0, t = 1; i < p; ++i){
			c[y[i]][x[i]][h[y[i]][x[i]]++] = t;
			for(int a = 0; answer == 0 && a < n; ++a){
				for(int b = 0; answer == 0 && b < n; ++b){
					if(h[a][b] == 0){ continue; }
					for(int j = 0; answer == 0 && j < h[a][b]; ++j){
						for(int d = 0; d < 26; ++d){
							int cx = b, cy = a, cz = j, l = 0;
							while(
								0 <= cx && cx < n && 0 <= cy && cy < n &&
								0 <= cz && cz < n && l < m)
							{
								if(c[cy][cx][cz] != t){ break; }
								cx += dx[d]; cy += dy[d]; cz += dz[d];
								++l;
							}
							if(l >= m){
								answer = t;
								elapsed = i + 1;
							}
						}
					}
				}
			}
			t = -t;
		}
		if(answer == 0){
			cout << "Draw" << endl;
		}else{
			cout << (answer > 0 ? "Black " : "White ") << elapsed << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1236
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            bool ans = Enumerable.Range(0, n / 7 + 1).Any(x => (n - x * 7) % 4 == 0);
            Console.WriteLine(ans ? "Yes" : "No");
        }
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <string>
#include <cstdlib>


int main(void) {
    int n;
    int score_taro = 0;
    int score_hanako = 0;
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        std::string s1;
        std::string s2;
        std::cin >> s1 >> s2; 
        if (s1 > s2) {
            score_taro += 3;
        } else if (s2 > s1) {
            score_hanako += 3;
        } else {
            score_taro++;
            score_hanako++;
        }
    }
        std::cout << score_taro << " " << score_hanako << std::endl;
    return EXIT_SUCCESS;
}

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

typedef long long int ll;
typedef pair<ll, ll> pll;
typedef pair<char, char> pcc;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

pcc C[200005];
string S;
ll N, Q;

bool checkL(ll n)
{
    REP(i, Q)
    {
        if (C[i].first == S[n])
        {
            if (C[i].second == 'L')
                n--;
            else
                n = std::min(n + 1, N - 1);
            if (n < 0)
                return true;
        }
    }
    return false;
}
bool checkR(ll n)
{
    REP(i, Q)
    {
        if (C[i].first == S[n])
        {
            if (C[i].second == 'L')
                n = std::max(0LL, n - 1);
            else
                n++;
            if (n > N - 1)
                return true;
        }
    }
    return false;
}

int main()
{
    cin >> N >> Q;
    cin >> S;
    REP(i, Q)
    {
        cin >> C[i].first >> C[i].second;
    }

    ll left = 0;
    {
        //! 左に落ちる最大値
        ll ok = 0, ng = N;
        while (abs(ok - ng) > 1)
        {
            ll mid = (ok + ng) / 2;
            if (checkL(mid))
                ok = mid;
            else
                ng = mid;
        }
        if (ok == 0 && !checkL(0))
            ok = -1;
        left = ok + 1;
    }
    ll right = 0;
    {
        //! 左に落ちる最大値
        ll ok = N - 1, ng = -1;
        while (abs(ok - ng) > 1)
        {
            ll mid = (ok + ng) / 2;
            if (checkR(mid))
                ok = mid;
            else
                ng = mid;
        }
        if (ok == N - 1 && !checkR(N - 1))
            ok = N;
        right = N - ok;
    }
    cout << N - std::min(N, left + right) << endl;
    return 0;
}

Measured memory_bytes: 900
h,w = (int(x) for x in input().split())
ab = []
count = 0
for _ in range(h):
    a = input()
    a = a+'.'
    a=list(a)
    for i in a:
        if i == '#':
            count += 1
    ab.append(a)
ab.append(list('.'*w))

if count != h+w-1:
    print('Impossible')
    exit()
            
step = [[0, 0]]
 
while len(step) > 0:
    y, x = step.pop(0)
    if y == h-1 and x == w-1:
        print('Possible')
        exit()
    if ab[y+1][x] == '#' :
        step.append([y+1, x])
    elif ab[y][x+1] == '#' :
        step.append([y, x+1])

print('Impossible') 

Measured memory_bytes: 38384
#include <bits/stdc++.h>
typedef long long ll;

#define pll pair<ll,ll>
#define ff first
#define snd second
#define pb push_back
#define vll vector<ll>
#define vpll vector<pll>
#define endl "\n"
#define MOD 1000000007
using namespace std;

ll const N = 1e5+1;


void solve()
{
  ll n,m;
  cin>>n>>m;
  ll ans = 0;
  if(n>=2)
  {
          ans += (n*(n-1))/2;
  }
  if(m>=2)
  {
          ans += (m*(m-1))/2;
  }
  
  cout<<ans;
}
 
int main() {
            ios_base::sync_with_stdio(false);
            cin.tie(NULL);
	    int t=1;
	    //cin>>t;
	    while(t--)
	    {
	            solve();
	    }
	    return 0;
}

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

const ll maxs = 1e6+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e9;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second

int main(){
    //freopen("input00.txt","r",stdin);
    ll T = 1;
    //cin>>T;
    while(T--){
        ll a,b;
        cin>>a>>b;
        ll ans=-1;
        // ll A = floor( (25*8)/(double)100) ;
        // ll B = floor( 25/(double)10);
        // cout << A <<  " " << B << endl;
        for(ll i=1;i<1e6;i++){
            ll A = floor( (i*8)/(double)100) ;
            ll B = floor( (i)/(double)10);
            if(A == a and B == b){
                ans = i;
                break;
            }
        }    
        cout << ans ;   
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int inf = 1e9;

int main() {
	string S;
	cin>>S;
	string ans = "No";
	if(S[0]=='Y'&&S[1]=='A'&&S[2]=='K'&&S[3]=='I')ans="Yes";
	cout<<ans<<endl;
}

Measured memory_bytes: 256
def main():
    N,W = map(int, input().split())
    wv = [list(map(int, input().split())) for _ in range(N)]

    dp = [list([0] * (W+1)) for _ in range(N)]
    dp[0][wv[0][0]] = wv[0][1]

    for i in range(1,N):
        w = wv[i][0]
        if W < w:
            continue
        v = wv[i][1]
        for j in range(W+1):
            sum_w = j + w
            if sum_w <= W:
                dp[i][sum_w] = max(dp[i-1][sum_w], dp[i-1][j] + v)
            dp[i][j] = max(dp[i][j],dp[i-1][j])

    print(max(dp[-1]))

if __name__ == "__main__":
    main()

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

int main() {
    int N;
    cin >> N;

    int L[N * 2];
    for (int i = 0; i < N * 2; ++i) {
        cin >> L[i];
    }

    sort(L, L + N * 2);
    int ans = 0;
    for (int i = 0; i < N; ++i) {
        // L[2i]とL[2i+1]を組み合わせる
        ans += L[i * 2];
    }

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


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    cin >> n;
    VL a(n);
    REP(i,n) a[i] = lin();

    ll sum = abs(a[0]) + abs(a[n-1]);
    REP(i,n-1){
        sum += abs(a[i] - a[i+1]);
    }

    // cout << sum << endl;

    REP(i,n){
        ll ans = sum;
        if (i == 0){
            ans += abs(a[1]) - abs(a[0]) - abs(a[1] - a[0]);
        }else if (i == n - 1){
            ans += abs(a[n-2]) - abs(a[n-1]) - abs(a[n-1] - a[n-2]);
        }else{
            ans += abs(a[i+1] - a[i-1]) - abs(a[i+1] - a[i]) - abs(a[i-1] - a[i]);
        }
        printf("%lld\n", ans);
    }

    return 0;
}


Measured memory_bytes: 2048
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
int pl[200100];
int main(){
    int n,m,i,j,k,ans=0,len=1;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
      scanf("%d",&k);
      pl[k]=i;
    }
    for(i=1;i<n;i++)
      if(pl[i+1]>pl[i])len++;
        else ans=max(ans,len),len=1;
    ans=max(ans,len);
    cout<<n-ans<<"\n";
	return 0;
}


Measured memory_bytes: 1024
N = int(input())
p = list(map(int, input().split()))
t = list(map(int, input().split()))
res = 100000

for i in range(N+1):
    for j in range(N+1):
        for k in range(N+1):
            if N < t[0] * i + t[1] * j + t[2] * k:
                if res > p[0]*i + p[1]*j + p[2]*k:
                    res = p[0]*i + p[1]*j + p[2]*k
            else:
                d = (N-t[0]*i-t[1]*j-t[2]*k + t[3] - 1) // t[3]
                if res > p[0]*i + p[1]*j + p[2]*k + p[3]*d:
                    res = p[0]*i + p[1]*j + p[2]*k + p[3]*d
print(res)



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

int main() {
  long long a,b,x,y;
  cin>>a>>b>>x;
  if (a==0) y =(b/x) + 1;
  
  else y = (b/x) - ((a-1)/x);
  
  cout<<y<<endl;
    
  
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [int(a) for a in input().split()]

total = sum(A)//2
x0 = 0
for i in range(len(A)):
  p = (-1)**i
  x0 += (A[i]*p)/2

x0 = int(x0)
ans = [x0*2]
xp = x0
for a in A[:-1]:
  ans += [(a-xp)*2]
  xp = a-xp
result = [str(a) for a in ans]
print(' '.join(result))

Measured memory_bytes: 76260
#include <bits/stdc++.h>
using namespace std;
int main(void){
	int n,m,ans;
	cin>>n>>m;
	ans=n;
	int a[n];
	bool b[n];
	memset(b,true,sizeof(b));
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=0;i<m;i++){
		int q,e;
		cin>>q>>e;
		if(a[q-1]>=a[e-1]&&b[e-1]) b[e-1]=false,n--;
		if(a[e-1]>=a[q-1]&&b[q-1]) b[q-1]=false,n--;
	}
	cout<<n<<endl;
	return 0;
}

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


input = sys.stdin.readline
def IS(cb): return cb(input().strip())
def IL(cb): return [cb(s) for s in input().strip().split()]
def IR(cb, rows): return [IS(cb) for _ in range(rows)]
def ILL(cb, rows): return [IL(cb) for _ in range(rows)]


def solve():
    S = IS(str)
    print(S[:3])


solve()


Measured memory_bytes: 9080
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <random>
#include <unordered_map>
#define ll long long
#define fr(i,k,N) for(ll i=k; i<N;i++)
#define rep(i,N) for(ll i=0; i<N;i++)
#define alll(v) v.begin(),v.end()
using namespace std;
template <class X> void pr(X test){cout<<test<<endl;}
template <class X> void prr(X test){for(auto it:test){cout<<it;}cout<<endl;}

int main() {
    ll q;
    cin>>q;
    vector<ll> v(q);
    ll maxx =0;
    rep(i, q){
        ll tmp;
        cin>>tmp;
        v[i]=tmp;
        maxx = max(tmp,maxx);
        
    }
    double score = 2000000000;
    double mokuhyo = maxx/2.0;
    ll out = -1;
    rep(i, q){
        if(v[i] != maxx && score > abs(mokuhyo - v[i])){
            score = abs(mokuhyo - v[i]);
            out = v[i];
        }
    }
    cout << maxx << " " << out;
    
}



Measured memory_bytes: 1024
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 17;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define Se second
#define Fi first

int A[55];
int B[55];

bool chk1[55][55][55]; // 1~i

bool chk2[55][55];
bool tchk[55][55];
int main() {
	int N, i, j, k, l;
	scanf("%d", &N);
	for (i = 0; i < N; i++) scanf("%d", &A[i]);
	for (i = 0; i < N; i++) scanf("%d", &B[i]);

	for (i = 0; i <= 50; i++) chk1[0][i][i] = true;
	for (i = 1; i <= 50; i++) {
		for (j = 0; j <= 50; j++) for (k = 0; k <= 50; k++) chk1[i][j][k] = chk1[i - 1][j][k];
		for (j = 0; j <= 50; j++) {
			for (k = 0; k <= 50; k++) {
				if (chk1[i - 1][j%i][k]) chk1[i][j][k] = true;
			}
		}
	}
	
	for (i = 0; i < N; i++) if (!chk1[50][A[i]][B[i]]) return !printf("-1\n");

	for (i = 0; i <= 50; i++) chk2[i][i] = true;
	
	ll ans = 0;
	for (i = 50; i >= 1; i--) {
		for (j = 0; j < N; j++) {
			for (k = 0; k <= 50; k++) {
				if (!chk2[A[j]][k]) continue;
				if (chk1[i - 1][k][B[j]]) break;
			}
			if (k > 50) break;
		}
		if (j >= N) continue;

		ans += 1ll << (ll)i;
		for (j = 0; j <= 50; j++) for (k = 0; k <= 50; k++) tchk[j][k] = chk2[j][k];
		for (j = 0; j <= 50; j++) for (k = 0; k <= 50; k++) if (chk2[j][k]) tchk[j][k%i] = true;
		for (j = 0; j <= 50; j++) for (k = 0; k <= 50; k++) chk2[j][k] = tchk[j][k];
	}
	return !printf("%lld\n", ans);
}

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

#define ALL(c) std::begin(c), std::end(c)

using namespace std;
using ll = long long;

void solve() {
    vector<bool> bc(8, false);
    int free = 0;
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int in;
        cin >> in;
        if (in < 400)bc[0] = true;
        else if (in < 800)bc[1] = true;
        else if (in < 1200)bc[2] = true;
        else if (in < 1400)bc[3] = true;
        else if (in < 1600)bc[4] = true;
        else if (in < 2000)bc[5] = true;
        else if (in < 2400)bc[6] = true;
        else if (in < 3200)bc[7] = true;
        else ++free;
    }

    const int pre = count_if(ALL(bc), [](auto x) { return x; });
    cout << (pre ? pre : 1) << " " << pre + free << endl;

}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);

    solve();
    return 0;
}


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


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

    cout<<( n<1000 ? "ABC" : "ABD")<<endl;
    return 0;
}


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

#define rep(i,c) for(int i = 0; i < (int)c; ++i)
using llint = long long int ;
using namespace std;



int main(){
    double L;
    cin>>L;

    double S;
    S=(L/3)*(L/3)*(L/3);
    printf("%.10f",S);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using PII = pair<int, int>;
const int INF = numeric_limits<int>::max();

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

int main()
{
    int n; cin >> n;
    cout << (1000 - n % 1000) % 1000 << endl;
    return 0;
}


Measured memory_bytes: 3620
#include <stdio.h>
int f(int x) {
    return x * x;
}

int area(int d){
    int i;
    int x=0;
    int sum=0;
    
    for (i = 1; i < 600 / d; i++) {
        x += d;
        sum += d * f(x);
    }
    
    return sum;
}

int main(void){
    int d;
    while(scanf("%d\n", &d) != EOF) {
        printf("%d\n", area(d));
    }
    
    return 0;
}


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

using namespace std;
using ll =long long;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
const ll INF = 1LL << 60;

//Write From this Line

const int mod = 1e9+7;
int main()
{
	int x;
	cin >> x;
	//ru-tox kara tamesu
	int ans = 1 ;
	for(int i = 1 ; i * i <= x ; i++){
		int now = i ;
		if(now == 1) continue;
		while(now * i  <= x){
			now *= i ;
			chmax(ans,now);
		}
	}
	cout << ans << endl;
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;



int main()
{	
	for(int i=1;i<=9;i++)
	{
		for(int j=1;j<=9;j++)
		{
			cout<<i<<"x"<<j<<"="<<i*j<< endl;
		}
	}
	return 0;	
}


Measured memory_bytes: 3056
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>
#include <bitset>
#include <set>

using namespace std;
using ll = long long;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

const ll MOD = 1e9 + 7;
const ll INF = 1 << 30;
const ll INF2 = 9e18;
const double INF3 = 9e14;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define fr first
#define sc second


int main() {
	ll n, h, a[100010], b[100010], ans = 0;
	cin >> n >> h;
	priority_queue<ll, vector<ll>>pq;
	for (int i = 0;i < n;i++) {
		cin >> a[i] >> b[i];
		pq.push(b[i]);
	}
	sort(a, a + n);
	while (!pq.empty()) {
		ll b = pq.top();pq.pop();
		if (b <= a[n - 1]) {
			if (h%a[n - 1] == 0)cout << ans + h / a[n - 1] << endl;
			else cout << ans + h / a[n - 1] + 1 << endl;
			return 0;
		}
		ans++;
		h -= b;
		if (h <= 0) {
			cout << ans << endl;
			return 0;
		}
	}
	if (h%a[n - 1] == 0)cout << ans + h / a[n - 1] << endl;
	else cout << ans + h / a[n - 1] + 1 << endl;
}

Measured memory_bytes: 2676
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <locale>
#include <iomanip>

#define nl '\n'

using namespace std;

long long n, y, a=-1, b=-1, c=-1;
 
int main(){

    cin >> n >> y;

    for(long long i = 0; i < n+1; i++){
        for(long long j = 0; j < n-i+1; j++){
            if(i*10000 + j*5000 + (n-i-j)*1000 == y && (i + j + (n-i-j)) == n){
                a = i;
                b = j;
                c = n-i-j;
            }
            
        }
    }

    if(a < 0 || b < 0 || c < 0){
        cout << -1 << ' ' << -1 << ' ' << -1;
        return 0;
    }

    cout << a << ' ' << b << ' ' << c;




}

//g++ -std=c++14 comp.cpp -o b; ./b.exe

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

int main(){
int n; cin>>n;
int dp[45];
dp[0]=1; dp[1]=1;
for(int i=2;i<=45;i++){
    dp[i]=dp[i-2]+dp[i-1];
}
cout<<dp[n]<<endl;
}


Measured memory_bytes: 3080
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt(); //nという変数を作り、標準入力から数字を一つ読み取って、nに入れる
        int q = sc.nextInt();

        String s = sc.next();

        int[] l = new int[q];
        int[] r = new int[q];
        int[] t = new int[n];

        for (int i = 0; i < q; i++) {
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
        }

        for (int i = 0; i < n - 1; i++) {
            t[i + 1] = s.substring(i, i+2).equals("AC") ? t[i] + 1 : t[i];
        }

        for (int i = 0; i < q; i++) {
            int res = t[r[i] - 1] - t[l[i] - 1];

            System.out.println(res);
        }
    }
}


Measured memory_bytes: 93824
import java.util.*;

public class Main {
    public static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
        while(sc.hasNext()) {
            int m = sc.nextInt();
            int f = sc.nextInt();
            int r = sc.nextInt();
            if (m==-1&&f==-1&&r==-1) break;
            String ret;
            if (m==-1||f==-1) {
                ret = "F";
            } else if (m+f>=80) {
                ret = "A";
            } else if (m+f>=65) {
                ret = "B";
            } else if (m+f>=50) {
                ret = "C";
            } else if (m+f>=30) {
                if (r>=50) {
                    ret = "C";
                } else {
                    ret = "D";
                }
            } else {
                ret = "F";
            }
            
            System.out.println(ret);
        }
    }
}

Measured memory_bytes: 26092
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    string s;
    int K;
    cin >> s;
    cin >> K;
    set<string> st;
    st.insert(s.substr(0, K));
    int N = s.size();
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j <= i + K; j++) {
            st.insert(s.substr(i, j - i));
        }
    }

    set<string>::iterator it = st.begin();
    for (int i = 0; i < K - 1; i++) {
        it++;
    }
    cout << *it << endl;
    return 0;
}


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

def solve():
    from collections import deque

    N = int(input())
    Us = [[] for _ in range(N)]

    for i in range(N):
        _in = list(map(int, input().split()))
        if len(_in) == 2:
            continue
        u, k, Vs = _in[0], _in[1], _in[2:]
        Vs.sort()
        for v in Vs:
            Us[u-1].append(v-1)
        Us[u-1] = deque(Us[u-1])

    find = [0 for _ in range(N)]  # 発見時刻
    terminated = [0 for _ in range(N)]  # 終了時刻
    tim = [0]  # 経過時間

    def dfs(now):
        while Us[now]:
            nxt = Us[now].popleft()

            if find[nxt] != 0:
                continue

            tim[0] += 1
            find[nxt] = tim[0]

            dfs(nxt)

        if terminated[now] == 0:
            tim[0] += 1
            terminated[now] = tim[0]

    for i in range(N):
        if find[i] == 0:
            tim[0] += 1
            find[i] = tim[0]
            dfs(i)

    for i in range(N):
        print(i+1, find[i], terminated[i])


if __name__ == "__main__":
    solve()



Measured memory_bytes: 6108
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const double PI = 3.1415926535897932;
const int MOD = 1e9 + 7;

//cin.tie(0);ios::sync_with_stdio(false);
int main() {
  int h, w, k;
  cin >> h >> w >> k;
  vector<vector<char>> G(h);
  int black_count = 0;
  
  rep (i, h) {
    rep (j, w) {
      char ch;
      cin >> ch;
      if (ch == '#') black_count++;
      G[i].push_back(ch);
    }
  }

  int ans = 0;
  for (int y = 0; y < (1 << h); y++) {
    for (int x = 0; x < (1 << w); x++) {
      vector<vector<char>> tmp = G;
      int cnt = 0;
      for (int i = 0; i < h; i++) {
	if (y & (1 << i)) {
	  rep (j, w) {
	    if (tmp[i][j] == '#') {
	      tmp[i][j] = '.';
	      cnt++;
	    }
	  }
	}
      }
      for (int j = 0; j < w; j++) {
	if (x & (1 << j)) {
	  rep (i, h) {
	    if (tmp[i][j] == '#') {
	      tmp[i][j] = '.';
	      cnt++;
	    }
	  }
	}
      }
      if (black_count - cnt == k) ans++;
    }
  }

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


Measured memory_bytes: 3556
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
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(); }

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#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 EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

//文字列としての数字を
//整数数型に変換する関数
long long getint(string str) {
	long long ret = 0;

	for (int i = 0; i < str.size(); i++) {
		ret = ret * 10 +(str[i] - '0');
	}

	return ret;
}

int main() {

	string s; cin >> s;

	//一文字なら＋を入れる余地がないので、表示して終了
	if (s.size() == 1) {
		cout << s << endl;
		return 0;
	}
	

	//s[0] s[1] s[2]…という添字の向きだと扱いにくいのでひっくり返す
	//…s[2] s[1] s[0]になる
	reverse(s.begin(), s.end());

	long long ans = 0;

	//＋が入る隙間の数
	int l = s.size() - 1;

	//＋の有無のパターンを全列挙
	//ビットが立ってる位置には＋を入れる

	//…s[2] l[1] s[1] l[0] s[0]
	//という対応になっている
	for (int bit = 0; bit < (1 << l); bit++) {
		
		//各＋の間にある数字を表す文字列
		string tmp ="";

		tmp += s[0];
		
		//＋が入る隙間の位置i
		for (int i = 0; i < l; i++) {

			//＋を入れたので、文字列を数字置き換えて、答えに追加する
			if ((bit >> i) & 1) {
				ans += getint(tmp);
				tmp = s[i+1];
			}

			//＋を入れなかったので隙間の左の文字を追加する。
			else {
				tmp= s[i+1]+tmp;
			}

			//一番左の数字を最後に回収
			if (i == l - 1) {
				ans += getint(tmp);
			}
		}
	}

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

Measured memory_bytes: 256
H, W = map(int, input().split())

s = [input() for i in range(H)]
check = 0
for y in range(H):
    for x in range(W):
        if s[y][x] == '#':
            for dy, dx in [1, 0], [-1, 0], [0, 1], [0, -1]:
                if 0 <= y + dy <= H-1 and 0 <= x + dx <= W-1:
                    if s[y + dy][x + dx] == '#':
                        break
            else:
                check = 1
if check == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3316
N = int(input())
A = map(int, input().split())

is_approved = True

for A_i in A:
    if A_i%2==0:
        if A_i%3 != 0 and A_i%5 != 0:
            is_approved = False
            break

if is_approved:
    print("APPROVED")
else:
    print("DENIED")

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf_int = 1e9 + 100;
const ll inf_ll = 1e18;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double dbl;
#define pb push_back
const double pi = 3.1415926535898;
#define dout if(debug) cout
#define fi first
#define se second
#define sp setprecision
#define sz(a) (int(a.size()))
#define all(a) a.begin(),a.end()
bool debug = 0;
const int MAXN = 2e5 + 100;
const int LOG = 20;
const int mod = 1e9 + 7;
const int MX = 2e5 + 100;
typedef long long li;
const li MOD = 1000000000949747713ll;

struct point {
    ll k, b;
    point(){
        k = b = 0;
    }

    point(ll K,ll B){
        k = K;
        b = B;
    }
};

struct vertex {
    point p;
    vertex *l, *r;

    vertex() {
        l = r = NULL;
    }
};

vertex mem[MX];
int top_mem = 0;

inline vertex* get_new(point &cur) {
    assert(top_mem < MX);
    mem[top_mem].p = cur;
    return &mem[top_mem++];
}

ll calc(point &p, ll x) {
    return p.k * x + p.b;
}

vertex *update(vertex *v, int tl, int tr, point cur) {
    if (!v)
        return get_new(cur);
    if (tl == tr) {
        if (calc(cur, tl) < calc(v->p, tl)) {
            v->p = cur;
        }
        return v;
    } else {
        int tm = (tl + tr) >> 1;
        if (calc(cur, tm) < calc(v->p, tm)) {
            swap(v->p, cur);
        }

        if (calc(cur, tl) < calc(v->p, tl)) {
            v->l = update(v->l, tl, tm, cur);
        } else {
            v->r = update(v->r, tm + 1, tr, cur);
        }
        return v;
    }
}

ll get(vertex *v, int tl, int tr, int x) {
    if (!v)
        return inf_ll;
    if (tl == tr) {
        return calc(v->p, x);
    } else {
        int tm = (tl + tr) >> 1;
        ll cur = calc(v->p, x);
        if (x <= tm) {
            return min(cur, get(v->l, tl, tm, x));
        } else {
            return min(cur, get(v->r, tm + 1, tr, x) );
        }
    }
}


ll h[MAXN];

ll dp[MAXN];

void solve() {
    int n;
    ll c;
    cin >> n >> c;
    vertex *root = NULL;
    for (int i = 1; i <= n; ++i) {
        cin >> h[i];
    }
    int mx = 2e6;
    point p = {-2 * h[1], 1ll * h[1] * h[1]};
    root = update(root, 0, mx, p);

    for (int i = 2; i <= n; ++i) {
        dp[i] = c + h[i] * h[i];
        dout << i <<" - "<<dp[i]<<endl;
        dp[i] += get(root, 0, mx, h[i]);

        point p = {-2 * h[i], dp[i] + h[i] * h[i]};
        root = update(root, 0, mx,p);

        dout << i<<" - "<<dp[i]<<endl;
    }
    cout << dp[n];


}

signed main() {
#ifdef zxc
    debug = 1;
    freopen("../input.txt", "r", stdin);
#else

#endif //zxc
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout.setf(ios::fixed);
    cout.precision(20);

    int t = 1;

    while (t--)
        solve();
    dout << endl << (1.0 * clock() / CLOCKS_PER_SEC) << endl;
}


Measured memory_bytes: 9600
#include<iostream>
#include <algorithm>
#include <vector>
#include <deque>
using namespace std;


int main()
{
    // 整数の入力
    int a,b;
    cin >> a >> b;
    if (a + b == 15){
        cout << "+" << endl;
    }else if (a * b == 15){
        cout << "*" << endl;
    }else{
        cout << "x" << endl;
    }

    return 0;
}

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

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	bool flag = false; //逆かどうか
	deque<int> b;
	rep(i,n){
		//逆だったらまえ
		if(flag){
			b.push_front(a[i]);
		}
		//逆じゃなかったら後ろ
		else{
			b.push_back(a[i]);
		}
		flag = 1-flag;
	}
	if(flag)
		for(int i=b.size()-1;i>=0;i--)
			cout << b[i] << ' ';
	else
		rep(i,b.size())
			cout << b[i] << ' ' ;
	cout << endl;	
	return 0;
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, h, n, w;
    cin >> N;
    reps(th, 1, 3501) {
        reps(tn, 1, 3501) {
            ll a = N * th * tn;
            ll b = 4 * th * tn - N * tn - N * th;
            if (b <= 0) continue;
            if (a % b == 0) {
                w = a / b;
                h = th;
                n = tn;
                break;
            }
        }
    }
    printf("%lld %lld %lld\n", h, n, w);
    return 0;
}

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

using namespace std;
using ll = long long int;
using ull = unsigned long long int;
#define vll vector<ll>

#define FOR(i, b, e) for(int i = (b); i < (e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define REV(v) reverse((v).begin(), (v).end())
#define IN(v) cin >> (v);
#define VIN(v, n) REP(i, n) cin >> v[i];
#define OUT(v) cout << (v) << endl;
#define YN(b) OUT((b) ? "YES" : "NO")
#define Yn(b) OUT((b) ? "Yes" : "No")
#define yn(b) OUT((b) ? "yes" : "no")

const ll MOD = 1000000007;

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

  ll n, m, a, b;
  cin >> n >> m;
  ll h[n], hh[n];
  REP(i, n) {
    cin >> h[i];
    hh[i] = -1;
  }
  REP(i, m) {
    cin >> a >> b;
    a--;
    b--;
    hh[a] = max(hh[a], h[b]);
    hh[b] = max(hh[b], h[a]);
  }

  ll c = 0;
  REP(i, n) {
    if (h[i] > hh[i] || hh[i] == -1) c++;
  }

  cout << c << endl;

  return 0;
}

Measured memory_bytes: 5168
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	int n;
	
	cin >> n;

	int a[n];

	vector<int> odd;
	vector<int> even;

	rep(i, n)
	{
		cin >> a[i];
		if (i & 1)
		{
			even.pb(a[i]);
		}
		else
		{
			odd.pb(a[i]);
		}
	}

	if (n & 1)
	{
		//cout << "test" << endl;
		//cout << odd.size() << endl;
		for(int i = odd.size() - 1; i >= 0; i--)
		{
			cout << odd[i] << " ";
		}

		//cout << even.size() << endl;
		if (even.size() > 0)
		{
			for (int i = 0; i < even.size() - 1; i++)
			{
				cout << even[i] << " ";
			}
		}
		//cout << "1:" << even.size() << endl;
		if (even.size() >= 1)
		{
			cout << even[even.size() - 1] << endl;
		}
		else
		{
			cout << endl;
		}

		
	}
	else
	{
		for(int i = even.size() - 1; i >= 0; i--)
		{
			cout << even[i] << " ";
		}
		for (int i = 0; i < odd.size() - 1; i++)
		{
			cout << odd[i] << " ";
		}
		cout << odd[odd.size() - 1] << endl;
	}

	
	return 0;
}


Measured memory_bytes: 3956
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define INF      (int)1e9
#define MOD      (int)1e9+7
using namespace std;
typedef long long     llong;
typedef pair<int,int> pii;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;

int main(){
	int n;
	cin>>n;
	
	vi a(n);
	REP(i,n) cin>>a[i];
	sort(ALL(a));
	
	int cnt=1;
	int ans=0;
	for(int i=1;i<n;++i){
		if(a[i-1]==a[i]) cnt++;
		else{
			if(cnt%2) ans++;
			cnt=1;
		}
	}
	if(cnt%2) ans++;
	
	cout<<ans<<endl;
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  int X = 0;
  int Y = 0;
  int M;
  M = N;
  
  for (int i = 0; i < 9; i++) {
    X = M % 10;
    Y += X;
    M = (M - X) / 10;
  }    
  
    if (N % Y == 0)
      cout << "Yes" << endl;
    else if (N % Y != 0)
      cout << "No" << endl;
}


Measured memory_bytes: 256
#include <cstdlib>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  string S; cin >> S;
  int vmax = 0;
  int cnt = 0;
  set<char> cs = {'A', 'C', 'G', 'T'};
  for (char c : S) {
    if (cs.count(c)) ++cnt;
    else cnt = 0;
    vmax = max(vmax, cnt);
  }
  cout << vmax << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int n;
    scanf("%d",&n);
    int i,r;
    for(i=0;i<3;i++){
        r=n%10;
        n=n/10;
        if(r==7){
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n" );
    return 0;
}


Measured memory_bytes: 1664