akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=m-1; i>=n; i--)
#define SORT(v,n) do{sort(v,v+n);reverse(v,v+n);}while(0)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x,n/2)%MOD;
  return x%MOD*POW(x,n-1)%MOD;
}

ll POW2(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW2(x*x,n/2);
  return x*POW2(x,n-1);
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}

ll lcm(ll u, ll v) {
  return u*v/gcd(u,v);
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll KAI2(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI2(m-1);
}

ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll COM2(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI2(m)/KAI2(n)/KAI2(m-n);
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}

ll ORD(ll x,ll n)
{
  if(x==0)return INF;
  if(x%n!=0)return 0;
  return 1+ORD(x/n,n);
}

int main()
{
  string s;
  ll c,x=0,ans=0;
  cin >> s;
  c=s.length();
  while(c>=0){
    if(s[c]=='C'&&s[c-1]=='B'){
      x++;
      c-=2;
    }
    else if(s[c]=='A'){
      ans+=x;
      c--;
    }
    else{
      x=0;
      c--;
    }
  }
  printf("%lld",ans);
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define upperlimit 1000100
#define INF 1000000100
#define INFL 1000000000000000100
#define eps 1e-8
#define endl '\n'
#define sd(n) scanf("%d",&n)
#define slld(n) scanf("%lld",&n)
#define pd(n) printf("%d",n)
#define plld(n) printf("%lld",n)
#define pds(n) printf("%d ",n)
#define pllds(n) printf("%lld ",n)
#define pdn(n) printf("%d\n",n)
#define plldn(n) printf("%lld\n",n)
#define REP(i,a,b) for(i=a;i<=b;i++)
#define mp make_pair
#define pb push_back
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define F first
#define S second
#define clr(a) memset(a,0,sizeof(a))
using namespace std;

ll gcd(ll n1,ll n2){
    if(!n1)return n2;
    if(!n2)return n1;
    if(n1%n2==0)return n2;
    return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent){
    base%=mod;
    ll ans=1;
    while(exponent){
        if(exponent&1)ans=(ans*base)%mod;
        base=(base*base)%mod;
        exponent/=2;
    }
    ans%=mod;
    return ans;
}
int main()
{
    int a,n;
    cin>>n>>a;
    cout<<(n*n-a);
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int w, h, i, j;
	while (1)
	{
		scanf("%d%d", &w, &h);
		if (h + w ==0)
		{ 
		return 0; 
		}

		for (i = 1; i <= w; i++)
		{
			for (j = 1; j <= h; j++)
			{
				if (j % 2 == 1)
				{
					if (i % 2 == 1)
					{
						printf("#");
					}
					else
					{
						printf(".");
					}
				}
				else
				{
					if (i % 2 == 1)
					{
						printf(".");
					}
					else
					{
						printf("#");
					}
				}
			}
			printf("\n");
		}
		printf("\n");

	}
	return 0;
}


Measured memory_bytes: 2112
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
        int a2 = a * a;
        int a3 = a * a * a;
	  System.out.println(a + a2  +a3);
	  sc.close();
	}
}

Measured memory_bytes: 35804
n, w = map(int, input().split())
vw = [input().split() for _ in range(n)]
vw = [(int(x[0]), int(x[1]))for x in vw]

dp = [0 for _ in range(w+1)]

for i in range(n):
    for j in range(w):
        if j + vw[i][1] < w + 1:
            dp[j + vw[i][1]] = max(dp[j + vw[i][1]], dp[j] + vw[i][0])
print(max(dp))



Measured memory_bytes: 5928
#define _USE_MATH_DEFINES
  
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <memory.h>
#include <ctime>
#include <bitset>
#include <vector>
#include <string>
#include <queue>
  
using namespace std;

void solution() {
    int n, k;
    cin >> n >> k;
    vector <int> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    int sum = 0;
    for (int i = 0; i < k; i++) {
        sum += v[i];
    }
    cout << sum << endl;
}
  
/*-------------------*/
      
int main()
{
#ifdef Files
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    /*Test*/
    //freopen("input.txt", "w", stdout);
      
    double OcZ2X = clock();
#else
    //freopen("joke.in", "r", stdin);
    //freopen("joke.out", "w", stdout);
#endif
      
/*
　　     　 　          ∧_,,∧　　　
    　            ♪　  (・ω・)　♪
               ＿＿＿＿○＿＿つヾ＿＿＿＿＿
             /δ⊆・⊇ 。/†: :† /δ ⊆・⊇｡ /|
            |￣￣￣￣￣￣￣￣￣￣￣￣￣ | |
            |　　　*/solution();/* 　　| |
            |　　　　　　　　　　　　　 |
*/
       
#ifdef Time
double P2HxQ = clock();
printf("\n*** Total time = %.3f sec ***\n", (P2HxQ - OcZ2X) / CLOCKS_PER_SEC);
#endif
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

struct tri {ll a;ll b;ll d;};
bool bf(vector<tri> edge,ll V, ll s ,vector<ll>(&ans)) {

	ans.push_back(0);
	
	repn(i, V) { ans.push_back(INF); }

	ans[s] = 0;
	
	rep(i, V) {
		rep(j, edge.size()) {
			if (ans[edge[j].a] + edge[j].d < ans[edge[j].b] && ans[edge[j].a]!=INF) {
				ans[edge[j].b] = ans[edge[j].a] + edge[j].d;
				if (i == V - 1) { return false; }
			}
		}
	}

	return true;

}




int main() {

	ll N, M, P;
	cin >> N >> M >> P;

	vector<tri> edge(M + 1);


	repn(i, M) {
		cin >> edge[i].a >> edge[i].b >> edge[i].d;
	}

	vector<ll> g[MAX];

	repn(i, M) {
		g[edge[i].b].push_back(edge[i].a);
	}

	queue<ll> q;
	bool con[MAX] = {};
	con[N] = 1;
	q.push(N);

	while (!q.empty()) {
		ll v = q.front();
		rep(i, g[v].size()) {
			ll w = g[v][i];
			if (con[w] == 0) {
				con[w] = 1;
				q.push(w);
			}

		}
		q.pop();
	}

	vector<tri> subedge;

	repn(i, M) {
		if (con[edge[i].a] && con[edge[i].b]) {
			tri x;
			x.a = edge[i].a;
			x.b = edge[i].b;
			x.d = P - edge[i].d;
			subedge.push_back(x);
		}
	}

	vector<ll> ans;

	if (bf(subedge, N, 1, ans)) {
		cout << max(0,-ans[N]);
	}

	else { cout << -1; }

	system("PAUSE");


}


Measured memory_bytes: 25404
#include <iostream>
using namespace std;
int t,n,a[100];
int main(){
	int i,j,h,l,th,tl;
	while(cin >> t){
		for(i=0;i<t;i++){
			l = 0;
			h = 0;
			cin >> n;
			for(j=0;j<n;j++){
				cin >> a[j];
			}
			for(j=0;j<n-1;j++){
				tl = 0;
				th = 0;
				if(a[j] < a[j+1]){
					if(tl < (a[j+1] - a[j])) tl = a[j+1] - a[j];
					if(l < tl) l = tl;
				}
				else{
					if(th < (a[j] - a[j+1])) th = a[j] - a[j+1];
					if(h < th) h = th;
				}
			}
			cout << l << " " << h << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

sum=0
for i in range(N):
    if B[i] > A[i]:
        sum += A[i]
        B[i] = B[i] - A[i]
        A[i] = 0
        
        if B[i] <= A[i+1]:
            sum += B[i]
            A[i+1] = A[i+1] - B[i]
            B[i] = 0
        else: #A[i+1] < B[i]
            sum += A[i+1]
            A[i+1] = 0
            B[i] = B[i] - A[i+1]
    
    else: #B[i] <= A[i]
        sum += B[i]
        B[i] = 0
        A[i] = A[i] - B[i]

print(sum)


Measured memory_bytes: 19004
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<algorithm>

using namespace std;

class Tree {
    public:
    Tree(int n) : m_node(n) {
        for (int i = 0; i < n; i++) {
            m_node[i].parent = NIL;
            m_node[i].leftChild = NIL;
            m_node[i].rightSibling = NIL;
        }
    }
    ~Tree(){}

    void SetParent(int node, int parent) {
        m_node[node].parent = parent;
    }

    void SetLeftChild(int node, int leftChild) {
        m_node[node].leftChild = leftChild;
    }

    void SetRightSibling(int node, int rightSibling) {
        m_node[node].rightSibling = rightSibling;
    }

    void PrintOriginal() {
        for (int i = 0; i < m_node.size(); i++) {
            printf("%d, %d, %d, %d\n", i, m_node[i].parent, m_node[i].leftChild, m_node[i].rightSibling);
        }
    }

    void Print() {
        for (int i = 0; i < m_node.size(); i++) {
            PrintNode(i);
        }
    }

    void PrintNode(int node) {
        printf("node %d: parent = %d", node, m_node[node].parent);
        PrintDepth(node);
        PrintType(node);
        PrintChild(node);
    }

    void PrintDepth(int node) {
        int depth = 0;
        while (m_node[node].parent != NIL) {
            depth++;
            node = m_node[node].parent;
        }
        printf(", depth = %d", depth);
        return;
    }

    void PrintType(int node) {
        if (m_node[node].parent == NIL) {
            printf(", root");
            return;
        }
        if (m_node[node].leftChild != NIL) {
            printf(", internal node");
            return;
        } else {
            printf(", leaf");
            return;
        }
    }

    void PrintChild(int node) {
        if (m_node[node].leftChild == NIL) {
            printf(", []\n");
            return;
        }
        printf(", [%d", m_node[node].leftChild);
        node = m_node[node].leftChild;
        while(m_node[node].rightSibling != NIL) {
            printf(", %d", m_node[node].rightSibling);
            node = m_node[node].rightSibling;
        }
        printf("]\n");
    }

    private:
    static const int NIL = -1;
    typedef struct Node {
        int parent;
        int leftChild;
        int rightSibling;
    } Node;
    vector<Node> m_node;
};

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

    Tree t(n);

    for (int i = 0; i < n; i++) {
        int id, k;
        cin >> id >> k;
        int previousNode = -1;
        for (int i2 = 0; i2 < k; i2++) {
            int ci;
            cin >> ci;
            t.SetParent(ci, id);
            if (i2 == 0) {
                t.SetLeftChild(id, ci);
            }
            if (previousNode != -1) {
                t.SetRightSibling(previousNode, ci);
            }
            previousNode = ci;
        }
    }

    t.Print();

    return 0;
}



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

char numtochar(ll num) {
    return num+96;
}

void printvec(vector<ll> v) {
    for(int i = 0; i < v.size(); i++) {
        cout<<v[i] << " ";
    }
    cout << endl;
}

int main () {

    ll n; cin >> n;
    vector <ll> resp;
    vector <ll> weights;
    vector <ll> weights2;
    weights.push_back(1);
    ll cur = 26;
    ll sum = 1;
    ll i = 0;
    while (sum <= n) {
        
        weights2.push_back(cur);
        sum += cur;
        weights.push_back(sum);
        cur *= 26;
        i++;
    }

    ll j = 0;
    ll rem;
    while(n > 26) {
        rem = (n-weights[weights.size()-3-j]) / weights2[weights2.size()-2-j];
        resp.push_back(rem);
        n -= weights2[weights2.size()-2-j] * rem;
        j++;
    }
    resp.push_back(n);

    for(ll k = 0; k < resp.size(); k++) {
        cout << numtochar(resp[k]);
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3584
import sys
X, N = (int(x) for x in input().split())
num = list(int(x) for x in input().split())
num.sort()
if X in num:
    index = num.index(X)
    for i in range(1,N+2):
        # -
        if index-i >= 0:
            if num[index-i] != X-i:
                print(X-i)
                sys.exit()
        else:
            print(X-i)
            sys.exit()
        # +
        if index+i < N:
            if num[index+i] != X+i:
                print(X+i)
                sys.exit()
        else:
            print(X+i)
            sys.exit()
else:
    print(X)


Measured memory_bytes: 9208
# -*- coding: utf-8 -*-
def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))

    dp = [0, abs(h[0] - h[1])]
    for i in range(2, n):
        min_cost = float('inf')
        for j in range(max(i - k, 0), i):
            cost = dp[j] + abs(h[j] - h[i])
            if min_cost > cost:
                min_cost = cost
        dp.append(min_cost)


    print(dp[-1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 84748
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve(args);
    }

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int lange = 0;
        int max = 0;
        int min = 0;
        int tmpMin = 0;
        int trueMin = 0;

        Integer[] input = new Integer[a];
        for (int i=0;i<a;i++) {
        	input[i] = scanner.nextInt();
        }


        for (int j=0;j<a-b+1;j++) {
        	lange = input[b-1+j] - input[j];
    		min = input[j];
    		max = input[b-1+j];

    		if (min>=0) {
    			tmpMin = lange + min;
            }else if(max < 0) {
            	tmpMin = lange + Math.abs(max);
            }else {
            	tmpMin = lange + Math.min(max, Math.abs(min));
            }
    		if(j==0) {
    			trueMin = tmpMin;
    		}else {
    			if(trueMin>tmpMin) {
    				trueMin = tmpMin;
    			}
    		}
        }
        System.out.println(trueMin);

    }

    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";
        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public String next() {
            try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0);
                i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
}

Measured memory_bytes: 47700
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>

using namespace std;

const int MAX = 1200;
const int K_MAX = 15;
vector<int> Prime;
int dp[MAX][K_MAX][200];

void make(){
  int isPrime[MAX];
  memset(isPrime,true,sizeof(isPrime));
  for(int i = 2; i*i < MAX; i++)
    if(isPrime[i]) for(int j = 2; i*j < MAX; j++) isPrime[i*j]=false;

  for(int i = 2; i < MAX; i++)
    if(isPrime[i]) Prime.push_back(i);
}

void solve(){
  memset(dp,0,sizeof(dp));
  dp[0][0][0] = 1;
  
  for(int j = 1; j < K_MAX; j++)
    for(int k = 0; k < (int)Prime.size(); k++)
      for(int i = 0; i < MAX; i++)
	for(int x = 0; x <= k; x++){
	  if(j != 1 && x == k) break;
	  if(i-Prime[k] >= 0) dp[i][j][k] += dp[i-Prime[k]][j-1][x];
	}
}

int main(){
  make();
  solve();
  int n,k;
  while(cin >> n >> k && n+k){
    int sum = 0;
    for(int i = 0; i < 200; i++) sum += dp[n][k][i];
    cout << sum << endl;
  }
  return 0;
}

Measured memory_bytes: 15284
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=81;
const int z=12800;
bool dp[81][81][25601];
int n,m;
int a[max_n][max_n],b[max_n][max_n];
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++)scanf("%d",&a[i][j]);
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++)scanf("%d",&b[i][j]);
    }
    dp[1][1][a[1][1]-b[1][1]+z]=dp[1][1][b[1][1]-a[1][1]+z]=true;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            for(int k=0;k<=25600;k++){
                if(dp[i][j][k]==false)continue;
                if(i+1<=n)dp[i+1][j][k+a[i+1][j]-b[i+1][j]]=dp[i+1][j][k-a[i+1][j]+b[i+1][j]]=true;
                if(j+1<=m)dp[i][j+1][k+a[i][j+1]-b[i][j+1]]=dp[i][j+1][k-a[i][j+1]+b[i][j+1]]=true;
            }
        }
    }
    int ans=1000000000;
    for(int i=0;i<=25600;i++)if(dp[n][m][i])ans=min(ans,abs(i-z));
    printf("%d\n",ans);
    return 0;
}

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

int main()
{
    int A, B, M;
    cin >> A >> B >> M;
    vector<int> a(A), b(B);

    int amin = 100010;
    int bmin = 100010;

    for(int i = 0; i<A; i++){
        cin >> a[i];
        amin = min(amin, a[i]);
    }

    for(int i = 0; i<B; i++){
        cin >> b[i];
        bmin = min(bmin, b[i]);
    }

    int ans = amin + bmin;

    int x, y, c;

    for(int i = 0; i < M; i++){
        cin >> x >> y >> c;
        ans = min(a[x - 1] + b[y - 1] - c, ans);
    }

    cout << ans << endl;

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int r;
long long int d[205][205];
int x[8],y[8];
long long int ans=1e18;
void solve(int num,long long int tmp){
    if(num==r || tmp>ans)ans=min(ans,tmp);
    if(num==0){
        for(int i=0;i<r;i++){
            y[0]=i;
            solve(1,0);
        }
    }
    else{
        int z[r];
        for(int i=0;i<r;i++)z[i]=0;
        for(int i=0;i<num;i++)z[y[i]]=1;
        for(int i=0;i<r;i++){
            if(z[i]==0){
                y[num]=i;
                solve(num+1,tmp+d[x[y[num-1]]][x[y[num]]]);
            }
        }        
    }
}

int main(){
    int n,m;
    cin >> n >> m >> r;
    for(int i=0;i<r;i++){
        cin >> x[i];
        x[i]--;
    }
    long long int a,b,c;
    for(int i=0;i<n;i++)for(int j=0;j<n;j++)d[i][j]=1e9;
    for(int i=0;i<n;i++)d[i][i]=0;
    for(int i=0;i<m;i++){
        cin >> a >> b >> c;
        a--; b--;
        d[a][b]=c; d[b][a]=c;
    }
  for (int k = 0; k < n; k++){       // 経由する頂点
    for (int i = 0; i < n; i++) {    // 始点
      for (int j = 0; j < n; j++) {  // 終点
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
    solve(0,0);
    cout << ans;
}

Measured memory_bytes: 3968
from fractions import *
from math import *

def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    gcd_left = [a[0]]
    gcd_right = [a[-1]]
    for i in range(n-1):
        gcd_left += [gcd(gcd_left[-1], a[i+1])]
        gcd_right += [gcd(gcd_right[-1], a[-i-2])]
    gcd_right = gcd_right[::-1]
    ans = 1
    for i in range(n):
        if i == 0:
            ans = max(ans, gcd_right[i+1])
        elif i == n-1:
            ans = max(ans, gcd_left[i-1])
        else:
            ans = max(ans, gcd(gcd_left[i-1], gcd_right[i+1]))

    print(ans)

main()

Measured memory_bytes: 16120
using System;
using System.Collections.Generic;
using System.Linq;

class Solution
{
    static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        var n = vals[0];
        var m = vals[1];
        var d = vals[2];

        var ones = d == 0 ? n : Math.Min(d * 2, n);
        var twos = n - ones;
        var probability = (1 * ones + 2 * twos) / (double)n / n;
        var ave = (m - 1) * probability;

        Console.WriteLine(ave);
    }
}

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

#ifndef LOCAL
#define cerr dolor_sit_amet
#endif

#define mp make_pair
#define sz(x) ((int)((x).size()))
#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int , int > ipair;
typedef pair < ll , ll > lpair;
const int IINF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
const double DINF = numeric_limits<double>::infinity();
const int MOD = 1000000007;
const double EPS = 1e-9;
const int DX[] = { 1,  0, -1,  0,  1, -1,  1, -1};
const int DY[] = { 0,  1,  0, -1,  1, -1, -1,  1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll sqr(ll x) { return x*x; } ll sqr(int x) { return (ll)x*x; }
double sqr(double x) { return x*x; } ld sqr(ld x) { return x*x; }
mt19937 mmtw(960172);
ll rnd(ll x, ll y) { static uniform_int_distribution<ll> d; return d(mmtw) % (y - x + 1) + x; }

// ========================================================================= //

const int N = 100179;

int n;
char s0[N];
int a0[N];
int m;
vector<int> e[N];
bool vis[N];

int dfs(int v) {
    if (v == n || vis[v])
        return 0;
    vis[v] = true;
    int s = a0[v];
    s += dfs(n - v);
    for (int nv : e[v])
        s += dfs(nv);
    return s % 26;
}

int main() {
    ios::sync_with_stdio(false);

    scanf("%s", s0);
    n = strlen(s0);
    scanf("%d", &m);
    for (int i = 0; i < m; ++i) {
        int x, y;
        scanf("%d%d", &x, &y);
        --x;
        if (y == n) {
            y = x;
             x = 0;
        }
        if (x + y == n)
            continue;
        e[x].push_back(y);
        e[y].push_back(x);
    }
    for (int i = 0; i < n - 1; ++i)
        a0[i + 1] = ((int)s0[i+1] - (int)s0[i] + 26) % 26;
    dfs(0);

    for (int i = 0; i < n; ++i)
        if (dfs(i) != 0) {
            cout << "NO\n";
            return 0;
        }
    cout << "YES\n";

    return 0;
}


Measured memory_bytes: 7680
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>



/*以下便利なマクロを定義する。*/

#define if_forall(i, min, max, prop)\
	bool if_forall_condition=1;\
\
	for(i=min; i<=max; i=i+1)\
	{\
		if(!(prop))\
		{\
			if_forall_condition=0;\
			break;\
		}\
	}\
\
	if(if_forall_condition==1)\



#define if_exists(i, min, max, prop)\
	bool if_exists_condition=0;\
\
	for(i=min; i<=max; i=i+1)\
	{\
		if(prop)\
		{\
			if_exists_condition=1;\
			break;\
		}\
	}\
\
	if(if_exists_condition==1)\











/*以下便利な関数を定義する。*/



void ini_int(int a[], int num)
{
	int i=0;

	for(i=0; i<=num; i=i+1)
	{
		a[i]=0;
	}

}



void ini_char(char array[], int num)
{
	int i=0;

	for(i=0; i<=num; i=i+1)
	{
		array[i]='\0';
	}

}



int powi(int base, unsigned int exponent)
{
	int answer=1;

	answer=(int)pow((double)base, (double)exponent);

	return answer;
}



void sort_asc_int(int a[], int min, int max)
{
	int i, j;
	int dumy;

	for(i=min; i<=max; i=i+1)
	{
		for(j=i+1; j<=max; j=j+1)
		{
			if(a[i]>a[j])
			{
				dumy=a[i];
				a[i]=a[j];
				a[j]=dumy;
			}
		}
	}
}



void sort_des_int(int a[], int min, int max)
{
	int i, j;
	int dumy;

	for(i=min; i<=max; i=i+1)
	{
		for(j=i+1; j<=max; j=j+1)
		{
			if(a[i]<a[j])
			{
				dumy=a[i];
				a[i]=a[j];
				a[j]=dumy;
			}
		}
	}
}



int max_int(int a[], int min, int max)
{
	int i;
	int answer;

	answer=a[min];

	for(i=min+1; i<=max; i=i+1)
	{
		if(answer<a[i])
		{
			answer=a[i];
		}
	}

	return answer;
}



int min_int(int a[], int min, int max)
{
	int i;
	int answer;

	answer=a[min];

	for(i=min+1; i<=max; i=i+1)
	{
		if(answer>a[i])
		{
			answer=a[i];
		}
	}

	return answer;
}



bool containelement_int(int array[], int min, int max, int element)
{
	int i;
	bool answer=0;

	if_exists(i, min, max, array[i]==element)
	{
		answer=1;
	}

	return answer;
}



int count_differentelement_int(int array[], int min, int max)
{
	int i=min;
	int pickup[max];
	ini_int(pickup, max);
	int answer=0;

	for(i=min; i<=max; i=i+1)
	{
		if(containelement_int(pickup, 0, answer-1, array[i])==0)
		{
			pickup[answer]=array[i];
			answer=answer+1;
		}
	}

	return answer;
}



int count_equalelement_int(int array[], int min, int max, int element)
{
	int i;
	int answer=0;

	for(i=min; i<=max; i=i+1)
	{
		if(array[i]==element)
		{
			answer=answer+1;
		}
	}

	return answer;
}











int main()
{

	int A[4];
	A[0]=0;
	scanf("%d %d %d", &A[1], &A[2], &A[3]);
	sort_asc_int(A, 1, 3);
	if(A[1]==5 && A[2]==5 && A[3]==7)
	{
		printf("%s\n", "YES");
	}
	else
	{
		printf("%s\n", "NO");
	}

	return 0;

}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int cnt[30],r[30],n;
int main(){
	for(int i=0;i<30;i++)cnt[i]=1145141919;
	cin>>n;
	for(int u=0;u<n;u++){
		for(int j=0;j<30;j++)r[j]=0;
		string s;
		cin>>s;
		for(int i=0;i<s.size();i++){
			r[s[i]-'a']++;
		}
		for(int j=0;j<30;j++){
			cnt[j]=min(cnt[j],r[j]);
		}
	}
	for(int i=0;i<30;i++){
		for(int j=0;j<cnt[i];j++){
			char z=i+'a';
			cout<<z;
		}
	}
	cout<<endl;
	return 0;
}

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

int main(){
  int a;
  int b;
  cin >> a;
  cin >> b;
  cout << 6 - a - b << endl;
}

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

#define pb push_back
#define MAX 100005
#define ff first
#define ss second
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
int n;
double p[305][305][305], ev[305][305][305];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    vector<int> cnt(4);
    for(int i = 0; i < n; ++i) {
        int x;
        cin>>x;
        ++cnt[x];
    }
    p[cnt[1]][cnt[2]][cnt[3]] = 1;
    for(int c = n; c >= 0; --c) {
        for(int b = n; b >= 0; --b) {
            for(int a = n; a >= 0; --a) {
                if(a == 0 && b == 0 && c == 0) {
                    continue;
                }
                if(a + b + c > n) {
                    continue;
                }
                
                double p_waste = (double) (n - (a + b + c)) / n;
                double ev_waste = p_waste / (1 - p_waste) + 1;
                ev[a][b][c] += ev_waste * p[a][b][c];
                
                if(a != 0) {
                    double p_go = (double) a / (a + b + c);
                    p[a-1][b][c] += p[a][b][c] * p_go;
                    ev[a-1][b][c] += ev[a][b][c] * p_go;
                }
                
                if(b != 0) {
                    double p_go = (double) b / (a + b + c);
                    p[a+1][b-1][c] += p[a][b][c] * p_go;
                    ev[a+1][b-1][c] += ev[a][b][c] * p_go;
                }
                
                if(c != 0) {
                    double p_go = (double) c / (a + b + c);
                    p[a][b+1][c-1] += p[a][b][c] * p_go;
                    ev[a][b+1][c-1] += ev[a][b][c] * p_go;
                }
            }
        }
    }
    cout<<fixed<<setprecision(12)<<ev[0][0][0]<<"\n";
    return 0;
}

Measured memory_bytes: 438528
N,A,B = map(int,input().split())
S = list(input())
cnt_a = 0
cnt_b = 0
for i,moji in enumerate(S):
    if moji == "c":
        print("No")
    elif moji == "a":
        if cnt_a < A+B:
            print("Yes")
            cnt_a += 1
        else:
            print("No")
    else:
        if cnt_a < A+B and cnt_b < B:
            print("Yes")
            cnt_a += 1
            cnt_b += 1
        else:
            print("No")


Measured memory_bytes: 4704
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();
		long[] a = new long[3 * N];
		for(int i = 0; i < 3 * N; i++) a[i] = sc.nextLong();
		Arrays.sort(a);
		int ind = 0;
		long ans = 0;
		for(int i = 3 * N; i - 2 > ind; i -= 2) {
			ans += a[i - 2];
			ind++;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 98332
n, m = list(map(int, input().split()))
s = []
for i in range(m):
    a = list(map(int, input().split()))
    s.append(a)
p = list(map(int, input().split()))

ans = 0
for i in range(2**n):
    on = []
    for j in range(n):
        if((i >> j) & 1):
            on.append(1)
        else:
            on.append(0)
    count = 0
    for j in range(m):
        total = 0
        for k in range(s[j][0]):
            if on[s[j][k+1]-1] == 1:
                total += 1
    
        if total % 2 == p[j]:
            count += 1
    if count == m:
        ans += 1

print(ans)


Measured memory_bytes: 3064
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        scan.close();

        if(n > m) for(int i = 0; i < n;i++) System.out.print(Integer.toString(m));
        else for(int i = 0; i < m;i++) System.out.print(Integer.toString(n));
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll INF=(ll)1e18+10;
const double PI=acos(-1);

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};


int main() {
    int N;
    int a;
    cin>>N;
    int cnt=0;
    for (int i = 0; i < N; ++i) {
        cin>>a;
        if(a%2==1&&i%2==0) cnt++;
    }
    cout<<cnt<<endl;

    return 0;
}


Measured memory_bytes: 3620
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, T = map(int, readline().split())

    ans = INF
    for _ in range(N):
        c, t = map(int, readline().split())
        if t <= T and ans > c:
            ans = c
    
    if ans < INF:
        print(ans)
    else:
        print('TLE')
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;


int main() {
    int c1 = 0, c2 = 0;
    string s;
    cin >> s;
    string a(s.size(), 'a'), b(s.size(), 'a');
    a[0] = '1';
    b[0] = '0';
    for (int i = 1; i < s.size(); i++){
        if (i % 2 == 0){
            a[i] = '1';
        }else{
            a[i] = '0';
        }
        if (i % 2 == 0){
            b[i] = '0';
        }else{
            b[i] = '1';
        }
    }
    for (int i = 0; i < s.size(); i++){
        if (s[i] != a[i]){
            c1++;
        }
        if (s[i] != b[i]){
            c2++;
        }
    }
    if (c1 > c2){
        cout << c2 << endl;
    }else{
        cout << c1 << endl;
    }
}

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

int main() {
  int N;
  cin >> N;
  vector <tuple<string,int,int>> p(N);
  
  for (int i = 0; i < N; i++){
    string a;
    int b;
    cin >> a >> b;
    p.at(i) = make_tuple(a,b*(-1),i+1);
  }
  sort(p.begin(),p.end());
  
  for (int i = 0; i < N; i++){
    int a;
    tie(ignore,ignore,a) = p.at(i);
    cout << a << endl;
  }
}

Measured memory_bytes: 256
import sys
MAX_INT = int(10e12)
MIN_NUM = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

tenki = {"Sunny":"Cloudy","Cloudy":"Rainy","Rainy":"Sunny"}

s = S()
print(tenki[s])

Measured memory_bytes: 38256
/*input
13 17
BBABBBAABABBA
7 1
7 9
11 12
3 9
11 9
2 1
11 5
12 11
10 8
1 11
1 8
7 7
9 10
8 8
8 12
6 2
13 11
*/
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MX = 2e5 + 100;
unordered_set<int> G[MX];
bitset<MX> pass, Yeee;
string s;
bool OK = false;
int far[MX], TMD[MX], p = 0;
bool check(int n) {
    int a = 0, b = 0;
    for(auto it: G[n]) {
        if(s[it] == 'A') a ++;
        if(s[it] == 'B') b ++;
    }
    return a and b;
}
int dfs(int n, int p) {
   // cout << " dd " << n << endl;
    if(TMD[n]) return far[n];
    TMD[n] = ++p;
    far[n] = n;
    for(auto it: G[n]) {
        if(it == p) continue; 
        int tmp = dfs(it, n);
        if(TMD[tmp] <= TMD[n]) OK = true;
        if(TMD[tmp] < far[n]) far[n] = tmp;  
    }
    return far[n];
}
main () {
    int n, m; cin >> n >> m;
    cin >> s; s = " " + s;
    while(m --) {
        int a, b; cin >> a >> b;
        G[a].insert(b);
        G[b].insert(a);
    }
//     for(int i = 1; i <= n; i ++) {
//         for(auto it: G[i]) cout << it << ' '; cout << endl;
//     }
// return 0;
    queue<int> GG;
    for(int i = 1; i <= n; i ++) {
        if(!check(i)) {
            GG.push(i);
            pass[i] = true;
        //    cout << i << endl;
        }
    }
    while(GG.size()) {
        int p = GG.front(); GG.pop();
        //cout << "   " << p << endl;
        for(auto it: G[p]) {
           // cout << " itt " << it << endl;
            if(it == p) continue;
            G[it].erase(p);
            if(!pass[it] and !check(it)) {
                GG.push(it);
                pass[it] = true;
            }
        }
        G[p].clear();
    }
    //cout << "Yeee \n";
    for(int i = 1; i <= n; i ++) {
        if(!TMD[i]) {
            //cout << "      " << i << endl;
            dfs(i, -1);
            if(OK) return cout << "Yes", 0;
        }
    }
    cout << "No";
}

Measured memory_bytes: 34396
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int N;
    scan(N);
    auto a = new int[](N);
    auto b = new int[](N);
    auto c = new int[](N);
    foreach (i ; 0 .. N) {
        scan(a[i], b[i], c[i]);
    }
    auto dp = new int[][](N, 3);
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];

    foreach (i ; 1 .. N) {
        foreach (j ; 0 .. 3) {
            if (j == 0) {
                chmax(dp[i][j], max(dp[i - 1][1], dp[i - 1][2]) + a[i]);
            }
            else if (j == 1) {
                chmax(dp[i][j], max(dp[i - 1][0], dp[i - 1][2]) + b[i]);
            }
            else {
                chmax(dp[i][j], max(dp[i - 1][0], dp[i - 1][1]) + c[i]);
            }
        }
    }

    auto ans = max(dp[N - 1][0], dp[N - 1][1], dp[N - 1][2]);
    writeln(ans);
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 7420
#include<iostream>
#include<cmath>
#include<string>
#include<fstream>
#include<vector>
#include<algorithm>
#include<iomanip>
using namespace std;

long long snuke_num(long long n)
{
    long long ans =0;
    long long t=n;
    while(t!=0)
    {
        ans+=t%10;
        t=t/10;
    }
    return ans;
}

bool comp_sn(pair <long long, long double> p1, pair<long long, long double> p2)
{
    if(p1.second<p2.second) return true;
    else if(p1.second>p2.second) return false;
    else return p1.first<=p2.first;
}

int main()
{
    long long k;
    cin>>k;
    long double max=0;
    pair <long long, long double> a[15984];
    int count=0;
    long long temp;
    long long cur_max;
    for(int i=1; i<=999; i++)
    {
        for(int j=0; j<=15; j++)
        {
            //number = i9..9
            temp = i;
            for(int k=0; k<j; k++)
            {
                temp*=10;
                temp+=9;
            }
            a[count].first= temp;
            a[count].second= (long double)temp/(long double)snuke_num(temp);
            count++;
        }
    }
    //sorted according to sn
    sort(a, a+15984, comp_sn);
    /*
    for(int i=0; i<count; i++)
    {
        cout<<a[i].first<<" "<<a[i].second<<endl;
    }*/
    //if previous number is larger, with smaller sn, then skip current number
    cur_max =0;
    for(int i=0; i<15984; i++)
    {
        if(a[i].first>cur_max)
        {
            cout<<a[i].first<<endl;
            cur_max = a[i].first;
            k--;
        }
        if(k==0) break;
    }
	return 0;
}


Measured memory_bytes: 768
fn run() {
    proconio::input! {
        n: u64,
    }
    let mut ans = 0;
    let mut i = 1;
    while i * i <= n {
        let p = n / i;
        ans += i * p * (p + 1) * 2;
        i += 1;
    }
    i = n / i;
    while i > 0 {
        let x = n / i;
        let y = n / (i + 1);
        ans += i * (i + 1) * (x * (x + 1) - y * (y + 1));
        i -= 1;
    }
    ans >>= 2;
    println!("{}", ans);
}

fn main() {
    run();
}

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

typedef long long ll;
const ll INF = 1e9, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second
#define m_p make_pair

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n,sum,ans=INF;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  REP(i,-100,101){
    sum = 0;
    rep(j,n){
      sum += (a[j]-i)*(a[j]-i);
    }
    ans = min(ans, sum);
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
def flip_count_mem(r, c):
  if memory[r][c] < 0:
    memory[r][c] = flip_count(r, c)
  return memory[r][c]

def flip_count (r, c):
  if r == H - 1 and c == W - 1:
    if s[r][c] == "#":
      return 1
    else:
      return 0
  #右に行ったとき
  if c == W - 1:
    count_right = 10000
  else:
    count_right = flip_count_mem (r, c + 1)
    if s[r][c] == "#" and s[r][c + 1] == ".":
      count_right += 1
  #下に行ったとき
  if r == H - 1:
    count_down = 10000
  else:
    count_down = flip_count_mem (r + 1, c)
    if s[r][c] == "#" and s[r + 1][c] == ".":
      count_down += 1
  return min(count_right, count_down)

H, W = input().split()
W = int (W)
H = int (H)
s = []
for i in range(H):
  s.append(input())
memory = [[-1 for i in range(W)] for j in range(H)]
print (flip_count(0, 0))


Measured memory_bytes: 3316
#include "stdio.h"

int selectionSort(int A[], int n){
    int minj, t, sw = 0;
    for(int i = 0; i < n-1; i++){
        minj = i;
        for(int j = i; j < n; j++){
            if(A[minj] > A[j]) minj = j;
        }
        t = A[i]; A[i] = A[minj]; A[minj] = t;
        if(i != minj) sw++;
    }
    return sw;
}
int main(){
    int A[100], n, sw;
    scanf("%d", &n);
    for(int i=0;i<n;i++) scanf("%d", &A[i]);
    sw = selectionSort(A, n);
    for(int i = 0; i < n; i++){
        if(i > 0) printf(" ");
        printf("%d", A[i]);
    }
    printf("\n");
    printf("%d\n", sw);
    return 0;
}


Measured memory_bytes: 2112
fun main(args: Array<String>) {
    edpb()
}

fun edpb() {
    val (n, k) = readLine()!!.split(" ").map { it.toInt() }
    val heights = readLine()!!.split(" ").map { it.toInt() }

    val totalCostsToReach = Array(heights.size) { Long.MAX_VALUE }
    totalCostsToReach[0] = 0

    for (i in 1 until heights.size) {
        val minTotalCostToReach = (1..k).filter { jump -> i - jump >= 0 }.map { jump ->
            val jumpCost = Math.abs(heights[i] - heights[i - jump])
            jumpCost + totalCostsToReach[i - jump]
        }.min()!!

        totalCostsToReach[i] = minTotalCostToReach
    }

    println(totalCostsToReach[n - 1])
}


Measured memory_bytes: 124276
s=input()
cnta=0
cntb=0
cntc=0
for i in range(len(s)):
  if s[i]=='a':
    cnta+=1
  elif s[i]=='b':
    cntb+=1
  else:
    cntc+=1
if len(s)%3==0:
  if cnta==cntb==cntc:
    print('YES')
  else:
    print('NO')
else:
  if max(cnta,cntb,cntc)==min(cnta,cntb,cntc)+1:
    print('YES')
  else:
    print('NO')

Measured memory_bytes: 3188
s = input()
dp = [[0 for i in range(13)]]
if s[-1] != "?":
    dp[0][int(s[-1]) % 13] += 1
else:
    for k in range(10):
        dp[0][k % 13] += 1
        
d = [1]   
for i in range(1,len(s)):
    dp.append([0]*13)
    d.append(d[i-1]*10 % 13)
    for r in range(13):
        if s[-(i+1)] == "?":
            for k in range(10): 
                dp[i][(k * d[i] + r) % 13] += dp[i-1][r] % (10**9 + 7)
                
        else:
            dp[i][(int(s[-(i+1)]) * d[i] + r) % 13] += dp[i-1][r] % (10**9 + 7)

print(dp[len(s)-1][5]%(10**9+7))


Measured memory_bytes: 72028
#include<iostream>
#include<string>
#include<map>
#define int long long int

using namespace std;

signed main(){
    
    int n; cin >> n;
    int x = 1e17;
    for(int i = 0; i < 5; i++){
        int o; cin >> o;
        x = min(x, o);
    }
    // (a + b - 1) / b
    // a / b の切り上げ
    
    cout << (n + x - 1) / x + 4 << endl;
    return 0;
}


Measured memory_bytes: 256
s = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())

print(s[k-1])

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

int main()
{
  int n;
  cin >> n;
  int amount;
  
  int a[n];
  for(int i = 0; i < n; i++)
    cin >> a[i];
  
  sort(a, a+n, greater<int>());
  
  amount = 0;
  for(int i = 0; i < n; i++)
  {
    if (i%2 == 0)
     amount += a[i];
    else
      amount -= a[i];
  }
  cout << amount << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T> >;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repb(i, n) for(ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define reprb(i, a, b) for(ll i = (a)-1; i >= (b); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(unsigned long long x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class S, class T>inline bool chmax(S &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class S, class T>inline bool chmin(S &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n;
    cin >> n;
    vll a(n);
    ll allxor = 0;
    rep(i, n){
        cin >> a[i];
        allxor ^= a[i];
    }
    // XOR==0にする
    if(allxor == 0){
        cout << 0 << endl;
        return 0;
    }
    // used 1->0 2->-1
    vi used(n, 0);
    repb(i, 32){
        if((allxor & (1ll << i)) != 0){
            rep(j, n){
                if(a[j] == (1ll << i) && used[j] == 0){
                    used[j] = 2;
                    allxor ^= a[j];
                    a[j]--;
                    allxor ^= a[j];
                    break;
                }
                if(j == n-1){
                    cout << -1 << endl;
                    return 0;
                }
            }
        }else{
            rep(j, n){
                if(a[j] == (1ll << i) && used[j] == 0){
                    used[j] = 1;
                }
            }
        }
        rep(j, n){
            a[j] &= ((1ll << i) - 1);
        }
        dump(a, used);
    }
    cout << count(ALL(used), 2) << endl;
    return 0;
}

Measured memory_bytes: 1408
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    ab = [list(map(int, input().rstrip('\n').split())) for _ in range(n)]
    t = 0
    for i in range(n):
        a, b = ab[-i-1]
        a += t
        if a % b != 0:
            t += ((a + b - 1) // b * b - a)
    print(t)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 57308
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

using Cost=ll;
using Cap=ll;
struct Edge{int to,rev;Cap cap;Cost cost;};
typedef vector<Edge> Edges;
typedef vector<vector<Edge> > Graph;

void add_edge(Graph &g,int from,int to,ll cap,Cost cost=0){
  g[from].pb((Edge){to,(int)g[to].size(),cap,cost});
  g[to].pb((Edge){from,(int)g[from].size()-1,0,-cost});
}
Cost INF=2e11;

//max_flow

vector<int> used;

Cap dfs(Graph &g,int v,int t,Cap f){
  if(v==t) return f;
  used[v]=1;
  Cap re=0;
	rep(i,g[v].size()){
    Edge &e=g[v][i];
    if(e.cap<=0||used[e.to])continue;
    Cap d=dfs(g,e.to,t,min(f,e.cap));
    if(d>0){
      e.cap-=d;
      g[e.to][e.rev].cap+=d;
      return d;
    }
  }
  return 0;
}

Cap max_flow(Graph &g,int s,int t){
  Cap sum=0,f;
	int V=g.size();
  while(1){
    used.resize(V);
    fill(all(used),0);
    sum+=f=dfs(g,s,t,INF);
    if(!f) return sum;
  }
}

int N;
LL as[114];

int main() {
  scanf("%d", &N);

  Graph g(N+2);
  LL sum = 0;
  reps(i, 1, N+1) {
    scanf("%lld", &as[i]);
    if (as[i] >= 0) {
      sum += as[i];
      add_edge(g, i, N+1, as[i]);
    } else {
      add_edge(g, 0, i, -as[i]);
    }
  }

  reps(i, 1, N+1) {
    reps(j, i+i, N+1) {
      if (j%i) continue;
      add_edge(g, i, j, INF);
    }
  }

  printf("%lld\n", sum-max_flow(g, 0, N+1));
}


Measured memory_bytes: 256