akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cassert>
#include <cstring>
#include <vector>

using namespace std;

vector<vector<vector<double>>> dp;
int n;

double find(int i, int j, int k){

    if(dp[i][j][k]!=-1) return dp[i][j][k];
 
    dp[i][j][k] = 0.0;
    if(i==0 && j==0 && k==0){
        return dp[i][j][k];
    }
    dp[i][j][k] += n;
    if(k){
        dp[i][j][k] += k*find(i,j+1,k-1);
    }
    if(j){
        dp[i][j][k] += j*find(i+1,j-1,k);
    }
    if(i){
        dp[i][j][k] += i*find(i-1,j,k);
    }
    dp[i][j][k] /= 1.0*(i+j+k);
    return dp[i][j][k];
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t = 1;
    while(t--){
        cin >> n;
        dp = vector<vector<vector<double>>> (n+1,vector<vector<double>>(n+1,vector<double>(n+1,-1)));
        
        vector<int> count(4,0);
        for(int i=0 ; i<n ; i++){
            int in;
            cin >> in;
            count[in]++;
        }
        cout.precision(16);
        cout << find(count[1],count[2],count[3]) << "\n";
    }
    return 0;
}



Measured memory_bytes: 219864
#include <stdio.h>

int main(void)
{
	int n, i, j, a[6];
	double x;

	for (i = 0; i < 6; i++)
		a[i] = 0;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
	{
		scanf("%lf", &x);
		if (x < 165.0)
			a[0]++;
		else if (x < 170)
			a[1]++;
		else if (x < 175)
			a[2]++;
		else if (x < 180)
			a[3]++;
		else if (x < 185)
			a[4]++;
		else 
			a[5]++;
	}
	for (i = 0; i < 6; i++)
	{
		printf("%d:", i+1);
		for (j = 0; j < a[i]; j++)
		{
			printf("*");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 640
// package app;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Scanner;
import java.util.StringJoiner;
import java.util.stream.Stream;

public class Main {

    public static void main(final String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);

        // String S = sc.next();
        // long u = sc.nextLong();

        int D = sc.nextInt();
        int N = sc.nextInt();
        N = N == 100 ? 101 : N;
        int result = D == 0 ? N : (int)Math.pow(100, D) * N;

        System.out.println(result);
    }
}

Measured memory_bytes: 21844
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

class Main {

    public static void main( final String[] args ) {

	final Scanner stdin = new Scanner( System.in );

	while ( stdin.hasNextInt() ) {

	    final int n = stdin.nextInt();
	    final int s = stdin.nextInt();
	    final boolean[] visited = new boolean[ 10 ];
	    
	    final int ans = dfs( n, s, visited, 0, 0 );
	    System.out.println( ans );
	}
    }

    static int dfs( final int n, final int s, final boolean[] visited, final int sum, final int depth ) {

	if ( sum == s && depth == n ) {
	    return 1;
	} else if ( sum > s || depth > n ) {
	    return 0;
	}
	int limSum = sum;
	int limNum = 9;
	for ( int i = 0; i < n - depth; i++ ) {
	    while ( limNum > 0 && visited[ limNum ] ) {
		limNum--;
	    }
	    limSum += limNum * ( n - i );
	}
	if ( limSum < s ) {
	    return 0;
	}
	
	int comb = 0;
	for ( int i = 0; i <= 9; i++ ) {
	    if ( !visited[i] ) {
		visited[i] = true;
		comb += dfs( n, s, visited, sum + ( depth + 1 ) * i, depth + 1 );
		visited[i] = false;
	    }
	}
	return comb;
    }    
}

Measured memory_bytes: 21728
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c<'0' || c>'9'));
	if(c=='-') c=getchar(),f=-1;
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	ll f=1;
	while((c=getchar())!='-' && (c<'0' || c>'9'));
	if(c=='-') c=getchar(),f=-1;
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=1000+10;
char s[maxn];
int main(){
	scanf("%s",s+1);
	int n=strlen(s+1);
	int ans=0;
	REP(i,1,n)ans+=s[i]-'0';
	printf("%d\n",max(ans,9*(n-1)+s[1]-'0'-1));
	return 0;
}


Measured memory_bytes: 256
n, m = [int(el) for el in input().split(' ')]
df = []
for i in range(m):
	df.append(input().split(' '))

record = []
for i in range(n):
	record.append([0,0])

for i in range(m):
	x = df[i][1]
	q = int(df[i][0])
	if record[q-1][0] == 1:
		pass
	else:
		if x == "AC":
			record[q-1][0] = 1
		else:
			record[q-1][1] += 1

ans = 0
for i in range(n):
	ans += record[i][0]


pen = 0
for i in range(n):
	if record[i][0] > 0:
		pen += record[i][1]

print(ans, pen)

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

typedef long long int ll;

int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(ll i = 0;i < n;i++){
        cin >> a[i];
    }

    ll f = 0;
    if(a[0] > a[1]){
        f = -1;
    }
    else if(a[0] < a[1]){
        f = 1;
    }
    else{
        f = 0;
    }

    ll ans = 0;
    for(ll i = 0;i < a.size() - 1;i++){
        if((f == 0 || f == 1) && a[i] <= a[i + 1]){
            if(a[i] < a[i + 1]){
                f = 1;
            }
        }
        else if((f == 0 || f == -1) && a[i] >= a[i + 1]){
            if(a[i] > a[i + 1]){
                f = -1;
            }
        }
        else{
            ans++;
            i++;
            if(i < a.size() - 1){
                if(a[i] == a[i + 1]){
                    f = 0;
                }
                else if(a[i] < a[i + 1]){
                    f = 1;
                }
                else{
                    f = -1;
                }
            }
        }
    }

    ans++;

    cout << ans;

    return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<set>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f, mod=1000000007;

void read(int &x)
{
    char ch; bool ok;
    for(ok=0,ch=getchar(); !isdigit(ch); ch=getchar()) if(ch=='-') ok=1;
    for(x=0; isdigit(ch); x=x*10+ch-'0',ch=getchar()); if(ok) x=-x;
}

int main()
{
    char s[100]; scanf("%s",s);
    int a=(int)s[0]-'0'+1;
    if (s[1]>s[0] || (s[1]==s[0]) && (s[2]>s[0]))
        printf("%d\n",111*a);
    else
        printf("%d\n",111*(a-1));
    return 0;
}


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

int main() {
	const int Size = 1e5 + 10;
	ll N, K;
	cin >> N >> K;
	array<ll, Size> d;
	d.fill(0);
	for (int i = 0; i < N; ++i) {
		ll a, b;
		cin >> a >> b;
		d[a] += b;
	}

	ll sum = 0;
	for (int i = 0; i <= d.size(); ++i) {
		if (sum + d[i] >= K) {
			cout << i << endl;
			break;
		} else {
			sum += d[i];
		}
	}

	return 0;
}


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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A[] = new int[N];
		for (int i=0;i<N;i++) {
			A[i] = sc.nextInt();
		}
		Arrays.parallelSort(A);
		int sum =0;
		for (int i=N-1;i>=0;i-=2) {
			if (i==0) {
				sum +=A[0];
			} else {
				sum +=A[i]-A[i-1];
			}
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 35876
module Main where

import System.IO
import Data.Char

main :: IO ()
main = do
  n <- getLine
  let n' = (read :: String -> Int) n
      sn = sum . map ((\x -> x - 48) . ord) $ n

  putStrLn $ case (n' `mod` sn) of
               0 -> "Yes"
               otherwise -> "No"

Measured memory_bytes: 508
#include <stdio.h>

#define N 4000

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  int i;

  for ( ; ; )
  {
    unsigned long long int d[ N + 1 ] = { 0 };
    int f[ N + 1 ] = { 0 };
    int l[ N ];
    int lp = 0, c = 0;
    int n;

    scanf ( "%d", &n );
    if ( !n ) break ;

    for ( i = 0; i < n; ++i )
    {
      int no, price, num;

      scanf ( "%d%d%d", &no, &price, &num );
      d[ no ] += price * num;
      if ( !f[ no ] ) l[ lp++ ] = no;
      f[ no ] = 1;
    }

    for ( i = 0; i < lp; ++i )
    {
      if ( d[ l[ i ] ] >= 1000000 )
      {
        printf ( "%d\n", l[ i ] );
        ++c;
      }
    }

    if ( !c )
    {
      puts ( "NA" );
    }
  }

  return ( 0 );
}

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

typedef long long ll;
const ll INF = 1LL << 60;

int main(void){
    int N,K;
    cin >> N >> K;
    
    ll h[110000];
    ll dp[110000];
    
    for(int i = 0 ; i < N ; i++){
        cin >> h[i];
    }
    for(int i = 0 ; i < 110000 ; i++){
        dp[i] = INF;
    }
    
    dp[0] = 0;
    for(int i = 0 ; i < N ; i++){
        for(int j = 1 ; j <= K ; j++){
            dp[i+j] = min(dp[i+j] , dp[i] + abs(h[i] - h[i+j]));
        }
    }
    cout << dp[N-1] << endl;
}


Measured memory_bytes: 5276
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

const MOD:i64 = 1_000_000_007;

fn main() {
    let n:i64 = read();
    let m:i64 = read();
    if (n-m).abs() > 1 {
        println!("0");
    } else if (n-m).abs() == 1 {
        println!("{}", f(n) * f(m) % MOD);
    } else {
        println!("{}", 2* f(n) * f(m) % MOD);
    }
}

fn f(n:i64) -> i64 {
    (1..=n).fold(1, |acc, x| acc * x % MOD)
}

Measured memory_bytes: 2084
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>

int main(){
    int n;
    std::cin>>n;
    std::vector<int> d(n);
    for(auto i = d.begin();i != d.end();i++){
        std::cin>>*i;
    }

    std::sort(d.begin(), d.end());
    d.erase(std::unique(d.begin(), d.end()), d.end());

    std::cout<<d.size()<<std::endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char>cvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
int main()	{
  string s;
  int cnt=0;
  cin>>s;
  int n=s.size();
  rep(i,n){
    if(s[i]!=s[n-1-i])
      cnt++;
  }
  cout<<cnt/2<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <fstream>
using namespace std;
double pie=3.14159265358979;
long long mod=998244353;
//
int main(){
	int a,b,m;
	int A[100000];
	int B[100000];
	cin>>a>>b>>m;
	int ma=1e9+7;
	int mb=1e9+7;
	for(int i=0;i<a;i++){
		cin>>A[i];
		ma=min(ma,A[i]);
	}
	for(int i=0;i<b;i++){
		cin>>B[i];
		mb=min(mb,B[i]);
	}
	int ans=ma+mb;
	for(int i=0;i<m;i++){
		int x,y,c;
		cin>>x>>y>>c;
		x--;y--;
		ans=min(ans,A[x]+B[y]-c);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
import math
import collections
import fractions
import itertools
import functools
import operator
import bisect

def solve():
    n = int(input())
    cnt = 0
    for i in range(n):
        a, b = map(int, input().split())
        if a == b:
            cnt += 1
        else:
            cnt = 0
        if cnt > 2:
            print("Yes")
            exit()
    print("No")
    return 0

if __name__ == "__main__":
    solve()


Measured memory_bytes: 10444
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <climits>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <map>
#include <tuple>
#include <iostream>
#include <deque>
#include <array>
#include <set>
#include <functional>
#include <memory>
#include <stack>
#include <numeric>
#include <climits>
#include <cfloat>
#include <bitset>

struct Work {
	int delay;
	long long int pay;
};
int main() {
	int n, m; std::cin >> n >> m;
	std::vector<Work> works(n);
	for (auto& w : works) std::cin >> w.delay >> w.pay;
	std::sort(works.begin(), works.end(), [](const Work& a, const Work& b) {return a.delay < b.delay; });
	auto comparator = [](const Work& a, const Work& b) {return a.pay < b.pay; };
	std::priority_queue<Work, std::vector<Work>, decltype(comparator)> queue(comparator);
	long long int money = 0;
	int index = 0;
	for (auto day = 1; day <= m; ++day) {
		while (index < n && works[index].delay <= day) {
			queue.push(works[index++]);
		}
		if (!queue.empty()) {
			money += queue.top().pay;
			queue.pop();
		}
	}
	std::cout << money << std::endl;
}


Measured memory_bytes: 3956
#include "bits/stdc++.h"

using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long

int main()
{
  IOS;
  int n;
  cin >> n;
  int arr[n];
  for (int i=0; i<n; i++)
    {
      cin >> arr[i];
    }
  for (int i=0; i<n; i++)
    {
      if (arr[i]%2==0)
	{
	  if (arr[i]%3==0 || arr[i]%5==0)
	    {
	      continue;
	    }
	  else
	    {
	      cout << "DENIED" << endl;
	      return 0;
	    }
	}
    }
  cout << "APPROVED" << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int main(){
    ll n,k;
    cin >> n >> k;
    vector<int> a(n);
    vector<int> f(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> f[i];
    sort(a.begin(),a.end());
    sort(f.begin(),f.end(),greater<int>());
    ll left = -1;
    ll right = 1e12;
    while (left + 1 < right){
        ll r = (left + right)/2;
        ll c = 0;
        rep(i,n){
            c += max(0ll,a[i] - r/f[i]);
        }
        if (c > k) left = r;
        else right = r;
    }
    PRINT(right);
}


Measured memory_bytes: 1792
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double LD;
using namespace std;
const int INF = 2147483647;
const int INF2 = 0x3f3f3f3f;
const ll INF64 = 3e18;
const double INFD = 1e30;
const double EPS = 1e-10;
const long double PI = acosl(-1);
const int MOD = 1e9 + 7;
template <typename T>
inline T read() {
    T X = 0, w = 0;
    char ch = 0;
    while (!isdigit(ch)) {
        w |= ch == '-';
        ch = getchar();
    }
    while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
    return w ? -X : X;
}
const int MAXN = 1000005;
const int MAXV = 60;
int n, m, k;
int dr[4] = {1, 0, -1, 0};
int dc[4] = {0, 1, 0, -1};
int dr2[8] = {1, 1, 1, -1, -1, -1, 0, 0};
int dc2[8] = {1, 0, -1, 1, 0, -1, 1, -1};
int CASE = 1;

struct FenwickTree {
    FenwickTree() {}
    inline void increase(int r, int c, int x) {
        for (int i = r; i <= n; i += lowbit(i))
            for (int j = c; j <= m; j += lowbit(j)) {
                a[i][j] += x;
                b[i][j] += r * x;
                d[i][j] += c * x;
                e[i][j] += r * c * x;
            }
    }
    inline int getSum(int r, int c) {
        int ans = 0;
        for (int i = r; i; i -= lowbit(i))
            for (int j = c; j; j -= lowbit(j)) {
                ans += a[i][j] * (r + 1) * (c + 1);
                ans -= b[i][j] * (c + 1);
                ans -= d[i][j] * (r + 1);
                ans += e[i][j];
            }
        return ans;
    }
    int a[MAXN][MAXN], b[MAXN][MAXN], d[MAXN][MAXN], e[MAXN][MAXN];
    inline int lowbit(int x) { return x & (-x); }
};

int amod[MAXN];
int main() {
#ifdef LOCALLL
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif

    scanf("%d", &n);
    set<int> loop;
    amod[0] = 0;
    loop.insert(0);
    loop.insert(7);
    for (int i = 1; i <= n; i++) {
        amod[i] = (amod[i - 1] * 10 + 7) % n;
        if (amod[i] == 0) {
            printf("%d\n", i);
            return 0;
        }
    }
    printf("%d\n", -1);
    return 0;
}

Measured memory_bytes: 7636
#include "bits/stdc++.h"

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define EPS 1e-9


double AB(int tx,int ty,int sx,int sy){
    double x = tx-sx;
    double y = ty-sy;
    return sqrt( (x*x)+(y*y) );
}


double inner(int ax,int ay,int bx,int by){
	return ax*bx + ay*by;
}

bool isCross(int wx,int wy,int r,  int tx,int ty,int sx,int sy){
	//	cout<<tx<<" "<<sx<<" "<<wy<<" "<<ty<<" "<<sy<<" "<<wx<<endl;
	double vc = inner( tx-sx,ty-sy,wx-sx,wy-sy );
//	cout<<vc<<endl;
	if( vc <0 )
		if( AB(sx,sy,wx,wy)<=r+EPS )return true;
		else return false;
//	if( vc>=AB(sx,sy,tx,ty) )
	if( vc>=(sx-tx)*(sx-tx) + (sy-ty)*(sy-ty) )
		if( AB(sx,sy,wx,wy)<=r+EPS )return true;
		else return false;

    int cr = (tx-sx)*(wy-sy) - (ty-sy)*(wx-sx);
//    cout<<cr<<endl;
    double num = (double)cr/(double)( AB(tx,ty,sx,sy) );
//    cout<<fabs(num)<<" "<<r-EPS<<endl;
    if( fabs(num) < r+EPS )return true;

    return false;
}

int isInCircle(int wx,int wy,int r,  int tx,int ty,int sx,int sy){
    int ret=0;
    if( sqrt((wx-tx)*(wx-tx) + (wy-ty)*(wy-ty))<=r+EPS )ret++;
    if( sqrt((wx-sx)*(wx-sx) + (wy-sy)*(wy-sy))<=r+EPS )ret++;
    return ret;
}


int main(){
    while(1){
        int n,m;
        int wx[200],wy[200],r[200];
        int tx[1000],ty[1000],sx[1000],sy[1000];
        cin>>n;
        if(n==0)break;
        rep(i,n) cin>>wx[i]>>wy[i]>>r[i];

        cin>>m;
        rep(i,m) cin>>tx[i]>>ty[i]>>sx[i]>>sy[i];
    

        rep(i,m){
            bool flag=false;
            rep(j,n){
                int circle = isInCircle(wx[j],wy[j],r[j],tx[i],ty[i],sx[i],sy[i]);
                bool Cross = isCross(wx[j],wy[j],r[j],tx[i],ty[i],sx[i],sy[i]);
                if( (circle==0 && Cross) || circle==1 ){
                    flag = true;
                    break;
                }
            }
            if(flag)cout<<"Safe"<<endl;
            else cout<<"Danger"<<endl;
        } 
    }
}

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

int main()
{
	int n, m;
	priority_queue<int> a;
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		int t;
		cin >> t;
		a.push(t);
	}
	for (int i = 0; i < m; i++) {
		int x;
		x = a.top();
		a.pop();
		x /= 2;
		a.push(x);
	}
	long long sum = 0;
	for (int i = 0; i < n; i++) {
		sum += a.top();
		a.pop();
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <cstdio>
#include <bitset>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <string>
#include <algorithm>
#include <cmath>
#include <limits>

using namespace std;
using ll=long long;
using vint=vector<int>;
using pint=pair<int,int>;

const double EPS = 1e-9;
const int inf = numeric_limits<int>::max();

#define rep(i,n) for(int i=0;i<int(n);++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;--i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(i,a,b) for(int i=int(b-1);i>=int(a);--i)
#define SHOW(a) cout << #a << " = " << a << endl
#define ARR(a,n) for(int i=0;i<int(n);++i) cout << #a << "[" << i << "]" << " = " << a[i] << endl

void solve(){
	ll N, C;
	cin >> N >> C;
	ll x[100000+5] = {}, v[100000+5] = {};
	rep(i, N)
	  cin >> x[i] >> v[i];

	ll r[100000+5] = {}, l[100000+5] = {};

	r[0] = v[0] - x[0];
	REP(i, 1, N){
		r[i] = r[i-1] - x[i] + x[i-1] + v[i];
	}

	l[0] = v[N-1] - (C - x[N-1]);
	REP(i, 1, N){
		l[i] = l[i-1] - (C - x[N-i-1]) + (C - x[N-i]) + v[N-i-1];
	}

	ll rm[100000+5] = {}, lm[100000+5] = {};
	rm[0] = r[0];
	REP(i, 1, N){
		rm[i] = max(rm[i-1], r[i]);
	}

	lm[0] = l[0];
	REP(i, 1, N){
		lm[i] = max(lm[i-1], l[i]);
	}

	ll rr[100000+5] = {}, rl[100000+5] = {};
	REP(i,0,N-1){
		rr[i] = r[i] + lm[N-i-2] - x[i];
	}
	REP(i,0,N-1){
		rl[i] = l[i] + rm[N-i-2] - (C - x[N-i-1]);
	}

	ll maxs[5] = {};
	maxs[1] = *max_element(r,r+N);
	maxs[2] = *max_element(l,l+N);
	maxs[3] = *max_element(rr,rr+N-1);
	maxs[4] = *max_element(rl,rl+N-1);

	ll ans = *max_element(maxs, maxs+5);

	cout << ans << endl;

}

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

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
using i64 = long long;

int main()
{
  i64 m, k;
  cin >> m >> k;
  if (m == 1)
  {
    if (k == 0)
      cout << "0 0 1 1" << endl;
    else
      cout << -1 << endl;
    return 0;
  }
  if ((1 << m) <= k)
  {
    cout << -1 << endl;
    return 0;
  }
  cerr << (1 << m) << endl;
  for (i64 i = 0; i < (1 << m); i++)
    if (i != k)
      cout << i << " ";
  cout << k << " ";
  for (i64 i = (1 << m) - 1; 0 <= i; i--)
    if (i != k)
      cout << i << " ";
  cout << k << endl;
  return 0;
}


Measured memory_bytes: 1792
import numpy as np

N, D = list(map(int, input().strip().split()))
Points  = [list(map(int, input().strip().split())) for i in range(N)]

count = 0
for point in Points:
    if np.sqrt(point[0]**2+point[1]**2) <= D:
        count += 1
        
print(count)

Measured memory_bytes: 63344
import java.util.Scanner;

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

		int[] menu = new int[5];

		//入力
		for(int i=0; i<menu.length; i++) {
			menu[i] = sc.nextInt();
		}

		//最後に注文するもの
		int last = 0;
		for(int i=0; i<menu.length; i++) {
			int x = menu[i]%10;
			int y = menu[last]%10;
			if((y==0) || (x!=0 && x<y)) {
				last = i;
			}
		}

		int ans = 0;
		//時刻の計算
		for(int i=0; i<menu.length; i++) {
			if(i!=last) {
				int time = menu[i];
				if(time%10 != 0) {
					time = time - time%10 + 10;
				}
				//System.out.println(time);
				ans += time;
			}
		}
		ans += menu[last];

		System.out.println(ans);

		sc.close();
	}
}

Measured memory_bytes: 21716
# -*- coding: utf-8 -*-
"""
Created on Sun Jan 12 21:16:15 2020

@author: masat
"""

N, M = map(int, input().split())
p_list = []
s_list = []
for i in range(M):
    p, s = input().split()
    p_list.append(int(p))
    if s == "AC":
        s_list.append(True)
    else:
        s_list.append(False)

#問題番号ごとにひとつずつ、合計でN個の空のリストを用意する。
bucket_list = []
for i in range(N):
    bucket_list.append([])

"""
p_listのi番目の問題番号を取り出し、
bucket_listの対応する番号（問題番号-1）のリストに
s_listのi番目の結果をappendする。
"""
for i in range(M):
    bucket_list[p_list[i]-1].append(s_list[i])

"""
"""
accepted_answer = 0
penalty = 0

for i in range(N):
    penalty_candidate = 0
    for k in bucket_list[i]:
        if k:
            accepted_answer += 1
            penalty += penalty_candidate
            break
        else:
            penalty_candidate += 1

print("{} {}".format(accepted_answer,penalty))


Measured memory_bytes: 19564
#include<iostream>
#include<algorithm>
using namespace std;
#define N 100

struct Node{
    int k;int u;
};

int main(){
    int n,a[N + 1][N + 1],k,u,v;
    
    cin >> n;
    
    for(int i = 1;i <= n;i++){
        for(int j = 1;j <= n;j++){
            a[i][j] = 0;
        }
    }
    
    for(int i = 1;i <= n;i++){
        cin >> k >> u;
        for(int j = 0;j < u;j++){
            cin >> v;
            a[k][v] = 1;
        }
    }
    
    for(int i = 1;i <= n;i++){
        for(int j = 1;j <= n;j++){
            if(j != n)cout << a[i][j] << " ";
            else cout << a[i][j];
        }
        cout << endl;
    }
}


Measured memory_bytes: 3116
N = int(input())
C0, C1, C2, C3 = 0, 0, 0, 0
for i in range(N):
    Si = input()
    if Si == 'AC':
        C0 += 1
 
    elif Si == 'WA':
        C1  += 1
 
    elif Si == 'TLE':
        C2 += 1
 
    else:
        C3 += 1
 
print('AC x ' + str(C0))
print('WA x ' + str(C1))
print('TLE x ' + str(C2))
print('RE x ' + str(C3))

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

using namespace std;

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();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#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 range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

signed main(void){
    for(int n; cin >> n, n;){

        //(ダイアル) -> (回数)
        map<string, int> minDist;

        string before, after; cin >> before >> after;

        queue<string> q;
        q.push(before);
        minDist[before] = 0;

#define F first
#define S second

        int res = inf;
        while(!q.empty()){
            string cur_dial = q.front();
            q.pop();

            int cur_cnt = minDist[cur_dial];

            if(cur_dial == after){
                res = cur_cnt;
                break;
            }

            int cur_ind = 0;
            while(cur_dial[cur_ind] == after[cur_ind]) cur_ind++;

            if(cur_ind == n) continue;
            
            int delta = (after.at(cur_ind) - cur_dial.at(cur_ind) + 10) % 10;

            range(i, cur_ind, n){
                cur_dial[i] = (cur_dial[i] - '0' + 10 + delta) % 10 + '0';

                if(minDist.find(cur_dial) != minDist.end()) continue;

                minDist[cur_dial] = cur_cnt + 1;
                q.push(cur_dial);
            }
        }

        cout << res << endl;
    }

	return 0;
}

Measured memory_bytes: 2640
#include <bits/stdc++.h>
using namespace std;
struct Edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int> >;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define rrep(i,m, n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define mk make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
typedef long long ll;
const int INF = 2000000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
typedef unsigned int uint;
#include <bits/stdc++.h>
using namespace std;
ll ggd(ll a, ll b) {//最小公倍数，最大公約数
	if(a<b)swap(a,b);
	if (b == 0ll) {
		return a;			
	}
	return ggd(b, a % b);
}
ll lcm(ll number1,ll number2){
	return number1/ggd(number1,number2)*number2;	
}
int main(){
    ll n,m;
    std::cin >> n>>m;
    VEC(ll,a,n);
    std::vector<int> aa(n);
    rep(i,n)aa[i]=a[i];
    rep(i,n)a[i]/=2ll;
    for(;;){
        int cou=0;
        rep(i,n)if((a[i]%2)==0)cou++;
        if(cou==0)break;
        else if(cou==n){
            rep(i,n)a[i]=a[i]/2;
        }else{
            std::cout << 0 << std::endl;
            exit(0);
        }
    }
    
    rep(i,n)a[i]=aa[i]/2;
    ll dum=1ll;
    rep(i,n){
        dum=lcm(dum,a[i]);
        if(dum>m){
            std::cout << 0 << std::endl;
            exit(0);
        }
    }
    std::cout << (m/dum)-(m/(dum*2ll)) << std::endl;
    
}

Measured memory_bytes: 1408
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

func main() {
	a, b := readInt(), readInt()

	fmt.Println(lcm(a, b))
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

// -----------------------------------------------------------------

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 640
package main

import (
	"fmt"
	"math"
)

func main() {
	var n, x int
	fmt.Scan(&n)
	fmt.Scan(&x)

	dp := make([]int, n+1)
	dp[0] = 0
	co := 1
	for index := 1; index <= n; index++ {
		var nn int
		fmt.Scan(&nn)
		dp[index] = dp[index-1] + nn

		if dp[index] <= x {
			co++
		}
	}

	fmt.Println(co)

}

func Max(nums ...int) int {
	if len(nums) == 0 {
		panic("function max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}


Measured memory_bytes: 512
D,N=map(int,input().split())
a,b,c=[],[],[]
i=1
while len(a)<100:
	if i%100!=0:
		a.append(i)
	i+=1
i=100
while len(b)<100:
	if i%100==0:
		j=i//100
		if j%100!=0:
			b.append(i)
	i+=100
i=10000
while len(c)<100:
	if i%10000==0:
		j=i//10000
		if j%100!=0:
			c.append(i)
	i+=10000
if D==0:
	print(a[N-1])
elif D==1:
	print(b[N-1])
else:
	print(c[N-1])


Measured memory_bytes: 3188
#include <iostream>
#include <limits.h>
#include <queue>
#include <algorithm>
#include <map>
#include <cstring>
#include <vector>
#include <sstream>
#include <utility>

using namespace std;

typedef pair<string,int> P;


int n,q;
queue<P> qu;

void solve(){

  int t=0;
  
  while(!qu.empty()){
    P proc = qu.front();
    qu.pop();
    if(proc.second<=q){
      t += proc.second;
      cout<<proc.first<<" "<<t<<endl;
    }
    else{
      t += q;
      qu.push(P(proc.first,proc.second-q));
    }
  }
}


int main(){

  string name;
  int tm;

  cin>>n>>q;
  for(int i=0;i<n;i++){
    cin >> name >> tm;
    qu.push(P(name,tm));
  }
  solve();
 
  return 0;
}

Measured memory_bytes: 6308
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

ll Q, H, S, D;
ll N;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> Q >> H >> S >> D;
  cin >> N;
  N *= 4;

  vector<pair<ll, ll>> sizes = {
      make_pair(1, Q),
      make_pair(2, H),
      make_pair(4, S),
      make_pair(8, D),
  };

  ll ans = LL_INF;
  do {
    ll n = N;
    ll a = 0;
    for (int i = 0; i < 4; i++) {
      if (sizes[i].first <= n) {
        ll num = n / sizes[i].first;
        a += (sizes[i].second * num);
        n -= (sizes[i].first * num);
      }
    }
    if (n == 0) {
      ans = min(ans, a);
    }
  } while (next_permutation(sizes.begin(), sizes.end()));

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

class Prime
{
	ll i, iLimit;
public:
	bool isPrime(ll a);
};

bool Prime::isPrime(ll a)
{
	if (a == 1) return false;
	iLimit = (int)sqrt(a);
	for (i = 2; i <= iLimit; i++) if (a % i == 0) break;
	return (i == iLimit + 1 ? true : false);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	vector<int> res(100005);
	Prime p;
	for (int i = 1; i <= 100000; ++i) {
		bool elf = p.isPrime(i);
		if (elf) {
			bool ok = p.isPrime((i + 1) / 2);
			if (ok) res[i]++;
		}
		res[i + 1] += res[i];
	}
	int q; cin >> q;
	rep(ri, q) {
		int l, r;
		cin >> l >> r;
		int ans = res[r] - res[l - 1];
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 1024
import java.io.*;
import java.lang.reflect.Array;
import java.util.*;

public class Main {

    private static PrintWriter out;

    private static <T> void mprintln(T... ar) {
        for (T i : ar) {
            out.print(i + " ");
        }
        out.println();
    }

    public static void main(String[] args) throws FileNotFoundException {

        // Input from file
        // File inputFile = new File("JavaFile.txt");
        // File outputFile = new File("JavaOutputFile.txt");
        // FileReader fileReader = new FileReader(inputFile);
        // Here it ends

        MyScanner sc = new MyScanner();
        // MyScanner sc = new MyScanner(fileReader);

        out = new PrintWriter(new BufferedOutputStream(System.out)); // Output to console
        // out = new PrintWriter(new PrintStream(outputFile)); // Output to file

        getAns(sc);

        out.close();
    }

    /*
     *Don't use builtin function (Math.ceil)
     */

    static final long MOD = (long) (1e9 + 7);

    private static void getAns(MyScanner sc) {
        int a = sc.ni(), b = sc.ni(), c = sc.ni();
        a -= b;
        c -= a;
        if (c < 0) c = 0;
        out.println(c);
    }

    static class MyScanner {

        BufferedReader br;
        StringTokenizer st;

        MyScanner(FileReader fileReader) {
            br = new BufferedReader(fileReader);
        }

        MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nn() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        String nextLine() {
            String ans = "";
            try {
                ans = br.readLine();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            return ans;
        }

        char nc() {
            return nn().charAt(0);
        }

        int ni() {
            return Integer.parseInt(nn());
        }

        long nl() {
            return Long.parseLong(nn());
        }

        double nd() {
            return Double.parseDouble(nn());
        }

        int[] niArr0(int n) {
            int[] ar = new int[n];
            for (int i = 0; i < n; i++) {
                ar[i] = ni();
            }
            return ar;
        }

        int[] niArr1(int n) {
            int[] ar = new int[n + 1];
            for (int i = 1; i <= n; i++) {
                ar[i] = ni();
            }
            return ar;
        }

        long[] nlArr0(int n) {
            long[] ar = new long[n];
            for (int i = 0; i < n; i++) {
                ar[i] = nl();
            }
            return ar;
        }

        long[] nlArr1(int n) {
            long[] ar = new long[n + 1];
            for (int i = 1; i <= n; i++) {
                ar[i] = nl();
            }
            return ar;
        }
    }
}

Measured memory_bytes: 22740
x,n = map(int,input().split())
if n == 0:
  print(x)
else:
  p = list(map(int,input().split()))
  k = [i for i in range(-200,201)]
  for i in range(n):
    if p[i] in set(k):
      k.remove(p[i])
  minimum = 99999
  ans = 0
  for i in range(len(k)):
    if abs(k[i] - x )  < minimum :
      minimum = abs(k[i] - x)
      ans = k[i]
  print(ans)

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

using namespace std;

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

    int n;
    cin >> n;
    int arr[n];
    bool flag = false;
    for (int i = 0; i < n; i ++) {
        cin >> arr[i];
        if (arr[i] % 2 == 0) {
            if (arr[i] % 5 != 0 && arr[i] % 3 != 0)
                flag = true;
        }
    }
    if (flag){
        cout << "DENIED";
    } else {
        cout << "APPROVED";
    }

    return 0;
}

Measured memory_bytes: 256
K = int(input())
A, B = list(map(int, input().split()))

a = A // K
b = B // K
a_amari = A % K
b_amari = B % K
amari = min(a_amari, b_amari)
if (b - a) >= 1 or amari == 0:
    print('OK')
else:
    print('NG')


Measured memory_bytes: 9176
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto N = readln.chomp.to!int;
    foreach (x; N..1000) {
        if (x/100 == (x/10)%10 && (x/10)%10 == x%10) {
            writeln(x);
            return;
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (a).size() 
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,n) for(int i=1;i<=n;i++)
#define ford(i,n) for(int i=n;i>=0;i--) 
#define REP(i,a,n) for(int i=a;i<n;i++)
#define foreach(itr,c) for(__typeof((c).begin(),(c).end())itr=c.begin();itr!=c.end();itr++) 
#define fill(a,b) memset(a,b,sizeof(a))
#define re return
#define INF 1e9
#define LINF 1e18
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi > vpi; 
int main(){
	int n,k;
	cin>>n>>k;
	int a[n];
	rep(i,n){
		cin>>a[i];
	}
	sort(a,a+n);
	int ans=0;
	rep(i,k){
		ans+=a[i];
	}
	cout<<ans;
	re 0;
}

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

int main() {
  int n;
  int candy;
  cin >> n >> candy;
  long long int required = 0;
  vector<int> children(n);
  int ans = 0;
  for(int i=0;i<n;i++) {
    cin >> children[i];  
  }

  sort(children.begin(), children.end());

  for(int i=0;i<n;i++) {
    required += children[i];
    if(required == candy) {
      ans = i + 1;
      break;
    }

    if(required > candy) {
      ans = i;
      break;
    }

    if(i == n-1) ans = n - 1;
  }

  cout << ans << endl;
}

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

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

  if ((N-N/1000*1000)%111==0 || N%1110<10) {
    cout << "Yes" << endl;
  }
  else {
   cout <<"No" << endl;
  }
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  int n, k; cin >> n >> k;
  vi h(n);
  REP(i, n) cin >> h[i];

  vi dp(n);
  dp[0] = 0;
  FOR(i, 1, n) {
    RFOR(j, i-1, i-k) {
      if(j < 0) break;
      if(j == i-1) {
        dp[i] = dp[j] + abs(h[i] - h[j]);
      } else {
        dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
      }
    }
  }

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


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

const int MAXN = 1010;
int A[2][MAXN];
int K, n;
void shift(int * A) {
	memmove(A, A + 1, n << 2);
	A[n] = A[0];
}
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> K; n = (K + 3 >> 2) << 1;
	if (K == 1) return std::cout << "1\n1\n", 0;
	auto red = [] (int x) { return x > K ? x - n : x; };
	int idx = 0;
	for (int k = 0; k < 2; ++k)
		for (int j = 1; j <= n; ++j)
			A[k][j] = ++idx;
	shift(A[1]);
	std::cout << n << '\n';
	for (int i = 1; i <= n / 2; ++i) {
		for (int k = 0; k < 2; ++k)
			for (int j = 1; j <= n; ++j)
				std::cout << red(A[k][j]) << (" \n" [j == n]);
		shift(A[0]); shift(A[0]);
		shift(A[1]); shift(A[1]);
	}
	return 0;
}


Measured memory_bytes: 1152
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

int main() {

    int k;
    char s[101];
    scanf("%d %s", &k, s);

    int l = strlen(s);

    if (l <= k) {
        printf("%s", s);
    } else {
        for (int i = 0; i < k; i++) {
            printf("%c", s[i]);
        }
        printf("...");
    }

    return 0;
}


Measured memory_bytes: 1736
#include <iostream>
#include <string>

using namespace std;

int main()
{
    int n = 0;
    cin >> n;
    bool isOk = false;

    for (int i = 1; i <= 9; i++)
    {
        for (int j = 1; j <= 9; j++)
        {
            if (i * j == n)
            {
                isOk = true;
            }
        }
    }
    if (isOk)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

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

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

    string s;
    cin >> s;
    long long k;
    cin >> k;

    int n = s.size();
    for(int i = 0; i < k; i++){
        if(s[i] == '1');
        else{
            cout << s[i] << endl;
            return 0;
        }
    }
    cout << '1' << endl;

    return 0;
}

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

int main() {
	// your code goes here
	int k ;
	cin>>k ;
	string s ;
	cin>>s ;
	int l = s.length() ;
	if(l<=k)
	 cout<<s ;
	else 
	{
	    string temp = s.substr(0,k) ;
	    temp= temp+"..." ;
	    cout<<temp ;
	}
	  
	return 0;
}


Measured memory_bytes: 3624
N=int(input())

import math
ans=0

all=0
for i in range(1,N+1):
    all+=i

for i in range(1,N+1):
    for j in range(1,N+1):
        ans+=3*math.gcd(i,j)
        
ans=ans-2*all

for i in range(1,N-1):
    for j in range(i+1,N):
        for k in range(j+1,N+1):
            ans+=6*math.gcd(math.gcd(i,j),k)
            
print(ans)

Measured memory_bytes: 9216
#include <bits/stdc++.h>
#define ll long long int
#define F(i,j,k,in) for(int i=j;i<k;i+=in)
#define DF(i,j,k,in) for(int i=j;i>=k;i-=in)
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define PB push_back
#define ub upper_bound
#define lb lower_bound
#define ins insert
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll X;
    cin>>X;
    ll q,r;
    q=X/500;
    r=X%500;
    cout<<(q*1000)+(5*(r/5));
return 0;
}



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

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

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

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

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

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

    // input
    ll N, A, B;
    cin >> N >> A >> B;

    ll ans = min(N*A, B);
    p(ans);
    
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
 
class Main {
 
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      	String s = br.readLine();
        char[] c = s.toCharArray();
      	
      	for(int i=0;i<s.length();i++){
        	if(i%2 == 0){
            	System.out.print(c[i]);
            }
        }
      System.out.println();
        }
	}

Measured memory_bytes: 46916
import sys
sys.setrecursionlimit(10**6)
N = int(input())
G = [[] for _ in range(N+1)]
for _ in range(N-1):
    a, b = map(int, input().split())
    G[a].append(b)
    G[b].append(a)


d1 = [None] * (N+1)
dn = [None] * (N+1)


def dfs(v, d, d_list):
    d_list[v] = d
    for nv in G[v]:
        if d_list[nv] is None:
            dfs(nv, d+1, d_list)

dfs(1, 0, d1)
dfs(N, 0, dn)

cnt = 0
for i in range(1, N+1):
    if d1[i] <= dn[i]:
        cnt += 1
    else:
        cnt -= 1

if cnt > 0:
    print('Fennec')
else:
    print('Snuke')


Measured memory_bytes: 117296
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 1000000007;

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

  ll n, k;
  cin >> n >> k;

  ll minimum = 0;
  ll maximum = 0;
  ll ans = 0;
  for (int i = 0; i <= n; i++) {
    minimum += i;
    maximum += n-i;
    if (i+1 >= k) ans = (ans + (maximum - minimum + 1)) % mod;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
#define de cout << "debug" << endl;
#define pb push_back
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; }


int main() {
    cin.tie(0);    
	ios::sync_with_stdio(false);
    int X,Y,Z,K;
    cin >> X >> Y >> Z >> K;
    vector<ll> A(X),B(Y),C(Z);
    REP(i,X) cin >> A[i];
    REP(i,Y) cin >> B[i];
    REP(i,Z) cin >> C[i];
    vector<ll> AB;
    REP(i,X){
        REP(j,Y){
            AB.pb(A[i]+B[j]);
        }
    }
    sort ALL(AB);
    reverse ALL(AB);
    if(AB.size() > K){
        AB.erase(AB.begin()+K,AB.end());
    }

    vector<ll> ans;
    REP(i,AB.size()){
        REP(j,Z){
            ans.push_back(AB[i]+C[j]);
        }
    }
    sort ALL(ans);
    reverse ALL(ans);

    REP(i,K) cout << ans[i] << endl;
}

Measured memory_bytes: 43240